This post has been republished via RSS; it originally appeared at: Windows Dev AppConsult articles.
Blazor is one of fantastic technologies I think.
It will be shipped a part of .NET Core 3.0.
There are two different models:
- Server-side Blazor
This runs on server-side through SignalR.
- Client-side Blazor
This runs on browser using WebAssembly.
However, you can create apps on same programming model.
Of course, it is .NET Core, so you can create Blazor apps on Linux too.
Create a Hello world app on Linux
I have an Ubuntu VM on Azure, and I have been using the environments using Visual Studio Code Remote Development feature. It's really cool!!
NOTE: .NET Core 3.0 is still preview. Please install .NET Core 3.0 from here.
Let's create a project using following command:
$ dotnet new blazor -o BlazorHelloWorld
The command is to create a server-side blazor app.(In document, dotnet new blazor is a client-side blazor project template. However, in my case, it was created a server-side blazor project.)
And please type dotnet run!!
$ dotnet run
You can look the app from https://localhost:5001. When using Visual Studio Code Remote Development, please add FORWARDED PORTS setting, like following:
After access the address, you can see an app like below:
When displaying the app, there are few messages on Debugging tool of Web Browser.(I'm using Edge preview.)
It means the app is connecting to a server using WebSocket of SignalR.
And you will find WebSocket connection on the Network tab that name is _blazor?id=xxxxxx. If you selected it, then you would see many binary messages.
Server-side blazor is running on server side, it means the app manages many information for client like DOM tree, state, etc...
Web browser is just to render and communicate to the server.
Deploy to azure
You can deploy the app to Azure Web app on Linux(Of course, you can also deploy Azure Web app on Windows.)
Let's create Web app on Linux with Free plan.
And create a package to deploy the Web app using following command:
$ dotnet publish -c Release --self-contained -r linux-x64 $ cd bin/Release/netcoreapp3.0/linux-x64/publish $ zip -r app.zip .
After creating a zip package, you can deploy the app to azure using Azure CLI!
$ az webapp deployment source config-zip --resource-group <your resource group name> --name <your web app name>--src app.zip
After that, set "dotnet YourProjectName.dll" to <your web app> -> Configuration -> General settings -> Startup Command.
Congrats!! The Blazor app works on App Service on Linux. But unfortunately, WebSocket(SignalR) is unavairable. There are many http requests.
If you want to use WebSocket, an easy way is to use Azure Web app on Windows.
Blazor is really powerful technology to build Single Page Applications! It will be released a part of .NET Core 3.0 at Sep 2019.
It works on web standard technologies(not plugin).
Client-side blazor is not in this article, but you can try it and deploy to everywhere.
The following link is official documentation of Blazor. If you feel Blazor is interesting, then please read it.