Feb 16

Written by: Michael Washington
2/16/2019 10:26 AM  RssIcon

image

You can properly scale your Razor Components application by connecting it to an Azure SignalR Service.

Create SignalR Service

image

We will need a Azure SignalR Service.

If you do not already have a Azure SignalR Service, log into the Azure Portal, and select Create a resource and search for SignalR Service.

image

Click Create.

image

You can initially choose the Free tier.

image

After the service is created, select Keys, and copy the Connection String (you will need it in the later steps).

 

Create the Razor Components Application

 

image

Open Visual Studio 2019.

image

Create a new Razor Components project.

image

Hit F5 and run the project

image

The app will display

Stop debugging.

 

Add SignalR Service

image

Right-click on the Solution node and select Manage NuGet Packages for Solution.

image

Search for and install, into the Server project, Microsoft.Azure.SignalR

image

Open the Startup.cs file in the Server project.

Add the following using statement:

 

using Microsoft.AspNetCore.Components.Server;

 

Change the ConfigureServices method to the following:

 

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSignalR().AddAzureSignalR(
                "{{ Your Azure SignalR Services Connection String }}");
            services.AddRazorComponents<App.Startup>();
        }

Note: Replace {{ Your Azure SignalR Servces Connection String }} with the connection string you copied earlier.

 

In the Configure method, remove the following line:

 

            app.UseBlazor<App.Startup>();

 

Replace it with:

 

            app.UseAzureSignalR(route => route.MapHub<BlazorHub>(BlazorHub.DefaultPath));
            app.UseRazorComponents<App.Startup>();

 

 

image

When we run the application and use it, we can look in Azure and see the traffic.

 

Links

Blazor.net

Blazor 0.6.0 experimental release now available

Refactor server-side blazor startup to allow Azure SignalR. Fixes #1227

3 comment(s) so far...


Gravatar

Re: Connecting Razor Components to Azure SignalR Service

Thanks Michael, nice short article. So, you can use Azure SignalR without having your app hosted on Azure. Correct?

By Dave Vorgang on   2/19/2019 6:44 PM
Gravatar

Re: Connecting Razor Components to Azure SignalR Service

@Dave Vorgang - Yes, you can run your Razor Components app on your own server (or desktop), and still use the Azure SignalR Service

By Michael Washington on   2/19/2019 6:45 PM
Gravatar

Re: Connecting Razor Components to Azure SignalR Service

** UPDATE ** This is broken in .Net Core 3.0 preview 3, but they plan to fix it in preview 4. See: https://github.com/aspnet/AspNetCore/issues/8590

By Michael Washington on   3/16/2019 12:40 PM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 
Microsoft Visual Studio is a registered trademark of Microsoft Corporation / LightSwitch is a registered trademark of Microsoft Corporation