ASP.NET SignalR application is not working in Azure cloud service
Article
This article provides information about troubleshooting issues where ASP.NET SignalR application is not working in Azure Cloud Service.
Original product version: API Management Service Original KB number: 4464827
Note
Refer to the article on Azure Cloud Service Troubleshooting Series, this is the eighth scenario of the lab. Make sure you have followed the lab setup instructions for Visitor Tracker application as per this, to recreate the problem.
Symptoms
Visitor Tracker is an ASP.NET SignalR application that tracks the number of visitors accessing the website. Each user is given a unique tracking ID that is displayed on the browser as the user moves the mouse pointer. As new users keep on visiting the site, the other users will be able to see new tracking IDs on their browsers. Click on the below image to get an idea of the expected output.
But after few days the application stopped working i.e users are not able to see their tracking IDs as well as for the other users on the browser.
Troubleshoot steps
SignalR uses the WebSocket transport where available, and falls back to older transports (Server Sent Events, Forever Frame (for Internet Explorer only), Ajax long polling) where necessary - This is known as SignalR transport negotiation. Refer this article to know more. You can determine what transport your application is using by taking a fiddler or F12 browser trace.
Example of F12 developer trace:
From the above developer trace, you can see that client tried to connect over number of transports but all of them failed with 404 error. You can check the server response for the first negotiate request for which you got HTTP 200 response.
From the above network trace it's clear that client tried to connect over WebSocket but Server doesn't support it. Also note that for SignalR to use WebSocket, IIS 8 must be used, the server must be Windows Server 2012, or later, and WebSocket must be enabled in IIS. You are using Windows Server 2016 but you need to check if WebSocket is enabled in IIS or not. In order to confirm that, log in to one of the instances and opened Add Roles and Features Wizard from Server Manager.
Expand Web Server (IIS) role verify if WebSocket protocol was enabled:
In order to enable WebSocket feature you can use the below DISM command in a startup task, so that when the role starts it installs the WebSocket feature in IIS.
Change a JavaScript web app update mechanism from polling to real-time push-based architecture with SignalR Service, Azure Cosmos DB and Azure Functions. Use Vue.js and JavaScript to use SignalR using Visual Studio Code.
As a Windows Server hybrid administrator, you integrate Windows Server environments with Azure services and manage Windows Server in on-premises networks.