title | description | author | ms.service | ms.devlang | ms.topic | ms.custom | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|
Develop with ASP.NET - Azure SignalR Service |
A quickstart for using Azure SignalR Service to create a chat room with ASP.NET framework. |
vicancy |
azure-signalr-service |
csharp |
quickstart |
devx-track-csharp, mode-other, devx-track-dotnet |
09/28/2020 |
lianwei |
Azure SignalR Service is based on SignalR for ASP.NET Core 2.1, which is not 100% compatible with ASP.NET SignalR. Azure SignalR Service reimplemented ASP.NET SignalR data protocol based on the latest ASP.NET Core technologies. When you use Azure SignalR Service for ASP.NET SignalR, some ASP.NET SignalR features are no longer supported, for example, Azure SignalR doesn't replay messages when the client reconnects. Also, the Forever Frame transport and JSONP aren't supported. Some code changes and proper version of dependent libraries are needed to make ASP.NET SignalR application work with SignalR Service.
Refer to the version differences doc for a complete list of feature comparison between ASP.NET SignalR and ASP.NET Core SignalR.
In this quickstart, you learn how to get started with the ASP.NET and Azure SignalR Service for a similar Chat Room application.
[!INCLUDE quickstarts-free-trial-note]
[!INCLUDE Connection string security]
Having issues? Try the troubleshooting guide or let us know.
Sign in to the Azure portal with your Azure account.
Having issues? Try the troubleshooting guide or let us know.
[!INCLUDE Create instance]
Serverless mode isn't supported for ASP.NET SignalR applications. Always use Default or Classic for the Azure SignalR Service instance.
You can also create Azure resources used in this quickstart with Create a SignalR Service script.
Having issues? Try the troubleshooting guide or let us know.
While the service is deploying, let's switch to working with code. Clone the sample app from GitHub, set the SignalR Service connection string, and run the application locally.
-
Open a git terminal window. Change to a folder where you want to clone the sample project.
-
Run the following command to clone the sample repository. This command creates a copy of the sample app on your computer.
git clone https://github.com/aspnet/AzureSignalR-samples.git
Having issues? Try the troubleshooting guide or let us know.
-
Start Visual Studio and open the solution in the aspnet-samples/ChatRoom/ folder of the cloned repository.
-
In the browser where the Azure portal is opened, find and select the instance you created.
-
Select Keys to view the connection strings for the SignalR Service instance.
-
Select and copy the primary connection string.
-
Now set the connection string in the web.config file.
[!INCLUDE Connection string security comment]
<configuration> <connectionStrings> <add name="Azure:SignalR:ConnectionString" connectionString="<Replace By Your Connection String>"/> </connectionStrings> ... </configuration>
-
In Startup.cs, instead of calling
MapSignalR()
, you need to callMapAzureSignalR({YourApplicationName})
and pass in connection string to make the application connect to the service instead of hosting SignalR by itself. Replace{YourApplicationName}
to the name of your application. This name is a unique name to distinguish this application from your other applications. You can usethis.GetType().FullName
as the value.public void Configuration(IAppBuilder app) { // Any connection or hub wire up and configuration should go here app.MapAzureSignalR(this.GetType().FullName); }
You also need to reference the service SDK before using these APIs. Open the Tools | NuGet Package Manager | Package Manager Console and run command:
Install-Package Microsoft.Azure.SignalR.AspNet
Other than these changes, everything else remains the same, you can still use the hub interface you're already familiar with to write business logic.
[!NOTE] In the implementation an endpoint
/signalr/negotiate
is exposed for negotiation by Azure SignalR Service SDK. It will return a special negotiation response when clients try to connect and redirect clients to service endpoint defined in the connection string. -
Press F5 to run the project in debug mode. You can see the application runs locally. Instead of hosting a SignalR runtime by application itself, it now connects to the Azure SignalR Service.
Having issues? Try the troubleshooting guide or let us know.
[!INCLUDE Cleanup]
Important
Deleting a resource group is irreversible and that the resource group and all the resources in it are permanently deleted. Make sure that you do not accidentally delete the wrong resource group or resources. If you created the resources for hosting this sample inside an existing resource group that contains resources you want to keep, you can delete each resource individually from their respective blades instead of deleting the resource group.
Sign in to the Azure portal and select Resource groups.
In the Filter by name... textbox, type the name of your resource group. The instructions for this quickstart used a resource group named SignalRTestResources. On your resource group in the result list, click ... then Delete resource group.
After a few moments, the resource group and all of its contained resources are deleted.
Having issues? Try the troubleshooting guide or let us know.
In this quickstart, you created a new Azure SignalR Service resource and used it with an ASP.NET web app. Next, learn how to develop real-time applications using Azure SignalR Service with ASP.NET Core.
[!div class="nextstepaction"] Azure SignalR Service with ASP.NET Core