You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: articles/azure-signalr/signalr-tutorial-build-blazor-server-chat-app.md
+12-9Lines changed: 12 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,14 @@ description: In this tutorial, you learn how to build and modify a Blazor Server
4
4
author: vicancy
5
5
ms.service: azure-signalr-service
6
6
ms.topic: tutorial
7
-
ms.date: 05/22/2022
7
+
ms.date: 08/28/2024
8
8
ms.author: lianwei
9
9
ms.devlang: csharp
10
10
---
11
11
12
12
# Tutorial: Build a Blazor Server chat app
13
13
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:
15
15
> [!div class="checklist"]
16
16
> * Build a simple chat room with the Blazor Server app template.
17
17
> * Work with Razor components.
@@ -37,7 +37,10 @@ Ready to start?
37
37
38
38
## Build a local chat room in Blazor Server app
39
39
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.
41
44
42
45
1. Create a Blazor chat app:
43
46
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
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:
110
113
111
114
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.
112
115
@@ -363,7 +366,7 @@ Beginning in Visual Studio 2019 version 16.2.0, Azure SignalR Service is built i
363
366
}
364
367
```
365
368
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:
367
370
368
371
[](media/signalr-tutorial-build-blazor-server-chat-app/blazor-chat.gif#lightbox)
369
372
@@ -374,7 +377,7 @@ Beginning in Visual Studio 2019 version 16.2.0, Azure SignalR Service is built i
374
377
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.
375
378
376
379
> [!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 serversare 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*:
378
381
>
379
382
> ```json
380
383
> "Azure:SignalR:ServerStickyMode": "Required"
@@ -393,7 +396,7 @@ When you deploy the Blazor app to Azure App Service, we recommend that you use [
393
396
394
397
[  ](media/signalr-tutorial-build-blazor-server-chat-app/blazor-chat-dependency.png#lightbox)
395
398
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:
397
400
398
401
* Update [`HostingStartupAssembly`](/aspnet/core/fundamentals/host/platform-specific-configuration) to use Azure SignalR Service.
399
402
* 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 [
422
425
dotnet add package Microsoft.Azure.SignalR
423
426
```
424
427
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:
0 commit comments