Default Blazor template not working on Azure - c#

Making sure that you have all the following done: https://devblogs.microsoft.com/aspnet/asp-net-core-and-blazor-updates-in-net-core-3-0-preview-8/
If you create a new Project in VS 2019 and use the Hosted Blazor template and then without modification (once you have it building and working on your local machine) Publish it to Azure. You will see that when you go to the fetchdata page, that no data is returned when running in Azure, however locally it works fine.
This does not seem to be a CORS issue as all requests are from the same domain. I have tried modifying the web.config to remove WebDav. I have asked on github: https://github.com/aspnet/AspNetCore/issues/13630#issuecomment-527678673
They told me to ask here and think it's me.
Here is the site: http://daringclub.azurewebsites.net/fetchdata
If you load up the template, you literally have the exact same code.
I would expect that using the template and immediately publishing to azure without making any changes should just work out of the box.
Edit:
I've just upgraded to .net Core 3 Preview 9 and have been able to successfully publish the Blazor template (Client, Server and Shared version, I think it's called Blazor Client Hosted or something).
I now need to comment out code from my main site till stuff works, cause that's how I program ;)

As Henk provided, check if you have self-contained app and make sure Azure could host .net core 3.0 then publish it.
In the Azure Portal, go to your WebApp after deployment (or create one beforehand).
Go to Extensions and click Add and select ASP.NET Core 3.0 (x86 for the free hosting).
Also go to Configuration, General settings and enable Web Sockets, they're Off by default.
Refer to this SO thread.

Related

Blazor server side deployment http 500 error

i have a problem when i deploy my blazor app (self-contained or framework-dependent) to a private server.
App works properly on visual studio debug mode, i can process crud operations even on remote server.
However when i deploy the app, i get http 500 error and i cant find any additional information. None of the pages are opening.
I checked the _Host.cshtml and Startup.cs files. The app doesn't have complex pages or packages for now, only use asp net core identity with ef core.
Where should i look into first, what could you suggest?
https://i.stack.imgur.com/yN50q.png
Finally i find the solution.
When i deploy the app on azure, it says there is a error about mysqlconnector, and i delete ServerVersion.AutoDetect (Pomelo package), set the version by hand in Startup.cs and it works. But i don't know why it works.

How to electronize an ASP.NET Core hosted Blazor WebAssembly app

I have created a new Blazor WebAssembly project and made it ASP.NET Core hosted (so, Visual Studio created three projects, one for the server, the actual WebAssembly client project, as well as a class library holding types used by both apps). Then, I just followed the documentation at https://github.com/ElectronNET/Electron.NET to electronize the server app. In theory, everything should be fine.
Problems occur when I try to run the app via electronize start. The build fails with the following error.
...Microsoft.NET.ILLink.targets(143,5): error NETSDK1102: Optimizing assemblies for size is not supported for the select
ed publish configuration. Please ensure that you are publishing a self-contained app. ...
Error occurred during dotnet publish: 1
Of course, I can imagine what the actual problem is. The Electron build tries to publish the assemblies for the current target platform, which is x64 in my case, but this is not supported for blazor-wasm projects. What I basically want to achieve is that the client build output gets included with the electronized server app.
Update
The following command successfully builds the electronized app, if the PublishSingleFile and PublishReadyToRun properties are set to false. Though, this is far from optimal since it creates an app that comes with a performance penalty (increased load time).
electronize build /target win /PublishSingleFile false /PublishReadyToRun false
Sadly, the switches currently do not work with the electronize start command.

How to convert a .Net Core 2.2 / Angular 8 app to PWA

I can create and test a basic Angular app to PWA following the angular docs. However, I can't get a .NET Core 2.2 / Angular 8 app (originally created using the Visual Studio Angular SPA Template) to a Progressive Web App.
I'm struggling to find any online help on how to do this. Everything from Microsoft is about converting an MVC app to PWA - nothing about converting an Angular SPA / .NET Core project to a PWA. And everything from the Angular side says nothing about the .NET Core Visual Studio scenario.
What I've done so far is as PWA support to the angular piece with via ng add #angular/pwa (and followed the entire angular PWA / Service Worker tutorial)
There is a nuget package from Microsoft for a .net core service worker but best as I can tell, that's not for an angular SPA (since it includes a service worker but I assume the one created by the ng add #angular/pwa is what I need).
https://github.com/madskristensen/WebEssentials.AspNetCore.ServiceWorker
I've tried various configurations in startup.cs but nothing seems to work, including skipping the
spa.UseAngularCliServer(npmScript: "start");
and instead use
spa.UseProxyToSpaDevelopmentServer("http://localhost:8080")
and launched http-server -p 8080 -c -1 under the clientapp folder (per the Angular docs) manually (also tried launching it directly under the dist folder).
Neither the manifest nor the service worker loads after I publish to our IIS server (per chrome's dev tools).
If someone has a working version of startup.cs and other config files for this or some pointers it would much appreciated.
If you want a guide to create a PWA with Angular have a look at this article, where I explain the whole process step-by-step. Plus you will find a working Angular PWA example in Github.
The article is part of a series about PWAs, maybe you can have a look at them to get a better overview about this technology.
If you ran the schematic command: ng add #angular/pwa you should have already a service worker module installed on your client app. Plus a web manifest and a service worker config file (called ngsw-config.json) where you can specify caching strategies.
Therefore you should already be able to test your PWA locally, just be aware you need an http server and an Angular prod build to run the service worker locally, since ng serve does not work with the service worker.
You can run ng build --prod and copy the generated files:
ngsw.json
ngsw-worker.js
safety-worker.js
worker-basic.js
to the "src" folder.
Then, in angular.json, add them to the "assets" array like this:
*Don't forget to remove the files from src and from assets array for production

ASP.NET MVC Core Deployment via Visual Studio does not work

I am sorry to ask a question which doesn't have a specific problem, but I would be more than grateful if you could point the problem. (I can always provide other parts of my code which would be relevant to my question)
I am using Visual Studio to create my web application with ASP.NET MVC Core. All is good with the project and I can make it work on my localhost.
I bought a third party hosting service with Windows hosting (Plesk) and as far as I've asked them, they said their hosting plan supports ASP.NET Core.
For the deployment part, I've literally searched each and every source and tried various different methods but could not properly upload my files on ftp. Trying ASP.NET Core 1.0.0 version worked well and I uploaded a sample website, but since I am working with ASP.NET Core 1.1.0 now, I am unable to find a solution.
Here is what my publish profile looks like before hitting publish button:
I'm not really sure if I filled all the information correctly, but validation seems to work well.
And here is the log which I get after trying the publish via ftp method in visual studio:
Even though it seems to succeed, when I look at my ftp directory after this process, the files in visual studio project were never uploaded in the directory.
Any help is appreciated, thanks.
I have deploy the same on my server and it is working fine see the attached screenshot.

How to debug an ASP.NET 5 web app in local IIS not Express

So it is super easy to setup debugging for your 4.6 (and <) ASP.NET web app in your local IIS. However, I do not see any way to do this in ASP.NET 5. I see IIS Express, ef, and web. Am I missing something? How can I set it up so that I can push Play and have it pull up a Chrome tab and have full debugging of my web app in my local IIS?
If you meant Controller debugging, you just have to make sure you properly have your breakpoints at the lines of codes you've created. After that, all you have to do is to run via IIS Express and you're good to go, VS will automatically prompt you to take a look at the IDE when you have to perform a stepover or etc.
From there you'll be able to check on your code with the various debugging windows in the 'Debug' option on the top bar of VS.
By the way, if you made a thorough lookup on the state of local IIS with .NET Core, there is no way as of now to do so..
How to configure ASP.NET Core 1.0 to use Local IIS instead of IIS Express?
And to further emphasize the pointlessness of using local IIS, here's quote from this article:
However, with ASP.NET Core there's little to no reason to be running
full IIS during development. Why? Because ASP.NET Core applications
aren't actually running inside of IIS. Whether you running called from
IIS, IIS Express or whether you do dotnet run directly from the
command line - you are running the exact same code and in most cases
the exact same execution environment. Running inside of IIS really
doesn't buy you anything anymore that you can't easily simulate with a
command line environment.
Maybe not exactly what you need, but you can debug it.
Before you start debugging, you need to republish the project to the path specified in IIS.
Browse to any webpage of the app so the process starts.
Then inside your VS go to Debug -> Attach to process. Find and select dotnet.exe. There might be several of them, so ticking Show processes from all users could reveal a few more records.
For example, the pool I use on IIS for .net core apps runs under NetworkService identity so it is easy for me to identify the dotnet.exe process I need to attach to (Attach to Process popup has User Name column that contains identity info).
Finally, VS will start debugging. It's similar to the steps for .net framework + attaching to w3wp.exe

Categories