Notes to self: SignalR on IIS, behind a load balancer

  development

My quick notes on the tasks necessary to get a SignalR app working on multiple Windows Server 2012 IIS servers, behind a load balancer (in my case, Citrix NetScaler).

Detailed instructions are outside the scope of this blog post. I’m merely collecting all the steps and resources in one spot for my own future reference:

  1. in the dev environment (Visual Studio): in the app, install the SignalR NuGet package from https://www.nuget.org/packages/Microsoft.AspNet.SignalR/ (at time of writing, the version on NuGet was 2.2.2)

    • installing the SignalR NuGet package will also install Microsoft.AspNet.SignalR.Core, Microsoft.AspNet.SignalR.JS, Microsoft.AspNet.SignalR.SystemWeb, Microsoft.Owin.Host.SystemWeb, Owin, Microsoft.Owin, Microsoft.Owin.Security, Newtonsoft.Json, etc.

  2. in the dev environment: add SQL Server backplane to SignalR as per https://docs.microsoft.com/en-us/aspnet/signalr/overview/performance/scaleout-with-sql-server by installing NuGet package Microsoft.AspNet.SignalR.SqlServer (version 2.2.2 if using SignalR 2.2.2 as above), configure and test

  3. in the dev environment: install the CORS OWIN NuGet package Microsoft.Owin.Cors to the app, and add CORS settings to the SignalR startup class as per https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-javascript-client#how-to-establish-a-cross-domain-connection and https://cmatskas.com/signalr-cross-domain-with-cors/

  4. on the IIS servers: add “WebSocket Protocol” to all IIS servers if not already enabled, using Server Manager > “Add roles and features” > “Web Server (IIS)” > “Web Server” > “Application Development” as per https://stackoverflow.com/a/41892056

  5. on the IIS servers: deploy the app to all IIS servers

  6. on one IIS server: at this point there will be an issue with different SignalR connection tokens on different IIS servers; to fix this, generate a machine key for the app’s web.config, for example using IIS Manager; copy the machine key section (in configuration > system.web in the web.config file) to other IIS servers and back to the dev environment as per https://stackoverflow.com/a/43479633

    • this is needed so the same machine key is deployed on all IIS servers behind the load balancer, and the machine key is not missed when the app is re-deployed

  7. on the IIS servers: also related to SignalR connection tokens, run the app pool for the app on all IIS servers as the same domain (not local) user as advised in https://stackoverflow.com/a/43479633/116288

There’s additional SignalR troubleshooting tips at https://docs.microsoft.com/en-us/aspnet/signalr/overview/testing-and-debugging/troubleshooting.

Thomas’s “but it worked for me” disclaimer: before using any code you find on the internet, especially on this blog, take time to understand what the code does and test, test, test. I’m not responsible for damage caused by code from this blog, and don’t offer any support or warranty.