From 12e258e68978de24ae3987c48b4233189328a851 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 11 Dec 2023 14:38:08 +0200 Subject: [PATCH] docs: Update signalr.md --- doc/articles/signalr.md | 67 +++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/doc/articles/signalr.md b/doc/articles/signalr.md index c21c7a05a972..b727bc6f4a31 100644 --- a/doc/articles/signalr.md +++ b/doc/articles/signalr.md @@ -4,48 +4,49 @@ uid: Uno.Development.SignalR # SignalR -[SignalR](https://docs.microsoft.com/en-us/aspnet/core/signalr/introduction?view=aspnetcore-3.1) is an ASP.NET Core library that allows server-side code to be instantly pushed to the client. +[SignalR](https://learn.microsoft.com/aspnet/core/signalr/introduction?view=aspnetcore-7.0) is an ASP.NET Core library that allows server-side code to be instantly pushed to the client. -## Prerequisites -* Visual Studio 2019 or higher -* Azure account (to publish SignalR service) +## Prerequisites + +- Visual Studio 2019 or higher +- Azure account (to publish SignalR service) ## Steps 1. Create `ASP.NET Core web application` in Visual Studio and name it `UnoChat.Service`. -![project-template](Assets/project-structure.JPG) + ![project-template](Assets/project-structure.JPG) -2. Add [SignalR Hub](https://docs.microsoft.com/en-us/aspnet/core/tutorials/signalr?view=aspnetcore-3.1&tabs=visual-studio#create-a-signalr-hub) to your `[YourProjectName].Service` project in a `Hubs` folder. +2. Add [SignalR Hub](https://learn.microsoft.com/aspnet/core/tutorials/signalr?view=aspnetcore-7.0&tabs=visual-studio#create-a-signalr-hub) to your `[YourProjectName].Service` project in a `Hubs` folder. 3. In your `Startup.cs` file, add your `SignalR` service and a `CORS policy` to the `ConfigureServices` method. -``` csharp -public void ConfigureServices(IServiceCollection services) - { - services.AddRazorPages(); - services.AddSignalR(); - - services.AddCors(o => o.AddPolicy( - "CorsPolicy", - builder => builder - .AllowAnyOrigin() - .AllowAnyMethod() - .AllowAnyHeader() - ) - ); - } -``` -In your `Configure` method, add your CORS policy and `Hubs` endpoint - -``` csharp - app.UseCors("CorsPolicy"); - - app.UseEndpoints(endpoints => - { - endpoints.MapRazorPages(); - endpoints.MapHub("/yourProjectHub"); - }); -``` + ``` csharp + public void ConfigureServices(IServiceCollection services) + { + services.AddRazorPages(); + services.AddSignalR(); + + services.AddCors(o => o.AddPolicy( + "CorsPolicy", + builder => builder + .AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader() + )); + } + ``` + +4. In your `Configure` method, add your CORS policy and `Hubs` endpoint + + ``` csharp + app.UseCors("CorsPolicy"); + + app.UseEndpoints(endpoints => + { + endpoints.MapRazorPages(); + endpoints.MapHub("/yourProjectHub"); + }); + ``` You now have a SignalR service that you can use with your Uno application!