Skip to content

Commit 5ad77aa

Browse files
Merge pull request #285723 from Akhilesh-microsoft/ASR/tutorial_build_blazor_server_chat_app
[ASR: tutorial-build-blazor-server-chat-app]:Verified the article, reviewed the content, and fixed all minor editorial issues. Updated ms.date w.r.t freshness pass.
2 parents 9a27ba4 + a2273f6 commit 5ad77aa

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

articles/azure-signalr/signalr-tutorial-build-blazor-server-chat-app.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ description: In this tutorial, you learn how to build and modify a Blazor Server
44
author: vicancy
55
ms.service: azure-signalr-service
66
ms.topic: tutorial
7-
ms.date: 05/22/2022
7+
ms.date: 08/28/2024
88
ms.author: lianwei
99
ms.devlang: csharp
1010
---
1111

1212
# Tutorial: Build a Blazor Server chat app
1313

14-
This tutorial shows you how to build and modify a Blazor Server app. You'll learn how to:
14+
This tutorial shows you how to build and modify a Blazor Server app. You learn how to:
1515
> [!div class="checklist"]
1616
> * Build a simple chat room with the Blazor Server app template.
1717
> * Work with Razor components.
@@ -37,7 +37,10 @@ Ready to start?
3737

3838
## Build a local chat room in Blazor Server app
3939

40-
Beginning in Visual Studio 2019 version 16.2.0, Azure SignalR Service is built into the web application publish process to make managing the dependencies between the web app and SignalR service much more convenient. You can work in a local SignalR instance in a local development environment and work in Azure SignalR Service for Azure App Service at the same time without any code changes.
40+
Beginning in Visual Studio 2019 version 16.2.0, Azure SignalR Service is built into the web application publish process to make managing the dependencies between the web app and SignalR service much more convenient. You can work without any code changes at the same time:
41+
42+
* in a local SignalR instance, in a local development environment.
43+
* in Azure SignalR Service for Azure App Service.
4144

4245
1. Create a Blazor chat app:
4346
1. In Visual Studio, choose **Create a new project**.
@@ -106,7 +109,7 @@ Beginning in Visual Studio 2019 version 16.2.0, Azure SignalR Service is built i
106109
dotnet add package Microsoft.AspNetCore.SignalR.Client --version 3.1.7
107110
```
108111

109-
1. Create a new [Razor component](/aspnet/core/blazor/components/) called `ChatRoom.razor` under the `Pages` folder to implement the SignalR client. Follow the steps below or use the [ChatRoom.razor](https://github.com/aspnet/AzureSignalR-samples/tree/master/samples/BlazorChat/Pages/ChatRoom.razor) file.
112+
1. To implement the SignalR client, create a new [Razor component](/aspnet/core/blazor/components/) called `ChatRoom.razor` under the `Pages` folder. Use the [ChatRoom.razor](https://github.com/aspnet/AzureSignalR-samples/tree/master/samples/BlazorChat/Pages/ChatRoom.razor) file or perform the following steps:
110113

111114
1. Add the [`@page`](/aspnet/core/mvc/views/razor#page) directive and the using statements. Use the [`@inject`](/aspnet/core/mvc/views/razor#inject) directive to inject the [`NavigationManager`](/aspnet/core/blazor/fundamentals/routing#uri-and-navigation-state-helpers) service.
112115

@@ -363,7 +366,7 @@ Beginning in Visual Studio 2019 version 16.2.0, Azure SignalR Service is built i
363366
}
364367
```
365368

366-
1. Press <kbd>F5</kbd> to run the app. Now, you can initiate the chat:
369+
1. To run the app, press <kbd>F5</kbd>. Now, you can initiate the chat:
367370

368371
[ ![An animated chat between Bob and Alice is shown. Alice says Hello, Bob says Hi.](media/signalr-tutorial-build-blazor-server-chat-app/blazor-chat.gif) ](media/signalr-tutorial-build-blazor-server-chat-app/blazor-chat.gif#lightbox)
369372

@@ -374,7 +377,7 @@ Beginning in Visual Studio 2019 version 16.2.0, Azure SignalR Service is built i
374377
When you deploy the Blazor app to Azure App Service, we recommend that you use [Azure SignalR Service](/aspnet/core/signalr/scale#azure-signalr-service). Azure SignalR Service allows for scaling up a Blazor Server app to a large number of concurrent SignalR connections. In addition, the SignalR service's global reach and high-performance datacenters significantly aid in reducing latency due to geography.
375378

376379
> [!IMPORTANT]
377-
> In a Blazor Server app, UI states are maintained on the server side, which means a sticky server session is required to preserve state. If there is a single app server, sticky sessions are ensured by design. However, if there are multiple app servers, there are chances that the client negotiation and connection may go to different servers which may lead to an inconsistent UI state management in a Blazor app. Hence, it is recommended to enable sticky server sessions as shown below in *appsettings.json*:
380+
> In a Blazor Server app, UI states are maintained on the server side, which means a sticky server session is required to preserve state. If there is a single app server, sticky sessions are ensured by design. However, if multiple app servers are in use, the client negotiation and connection may be redirected to different servers, which may lead to an inconsistent UI state management in a Blazor app. Hence, it is recommended to enable sticky server sessions as shown in *appsettings.json*:
378381
>
379382
> ```json
380383
> "Azure:SignalR:ServerStickyMode": "Required"
@@ -393,7 +396,7 @@ When you deploy the Blazor app to Azure App Service, we recommend that you use [
393396
394397
[ ![On Publish, the link to Configure is highlighted.](media/signalr-tutorial-build-blazor-server-chat-app/blazor-chat-dependency.png) ](media/signalr-tutorial-build-blazor-server-chat-app/blazor-chat-dependency.png#lightbox)
395398
396-
The service dependency will carry out the following activities to enable your app to automatically switch to Azure SignalR Service when on Azure:
399+
The service dependency carries out the following activities to enable your app to automatically switch to Azure SignalR Service when on Azure:
397400
398401
* Update [`HostingStartupAssembly`](/aspnet/core/fundamentals/host/platform-specific-configuration) to use Azure SignalR Service.
399402
* Add the Azure SignalR Service NuGet package reference.
@@ -422,7 +425,7 @@ When you deploy the Blazor app to Azure App Service, we recommend that you use [
422425
dotnet add package Microsoft.Azure.SignalR
423426
```
424427
425-
1. Add a call to `AddAzureSignalR()` in `Startup.ConfigureServices()` as demonstrated below.
428+
1. Add a call to `AddAzureSignalR()` in `Startup.ConfigureServices()` as shown in the following example:
426429

427430
```cs
428431
public void ConfigureServices(IServiceCollection services)
@@ -444,7 +447,7 @@ When you deploy the Blazor app to Azure App Service, we recommend that you use [
444447
> "Azure": {
445448
> "SignalR": {
446449
> "Enabled": true,
447-
> "ConnectionString": <your-connection-string>
450+
> "ConnectionString": <your-connection-string>
448451
> }
449452
> }
450453
>

0 commit comments

Comments
 (0)