codezoo codezoo - 29 days ago 20
ASP.NET (C#) Question

SignalR: Cross-domain connections (CORS - Access Control Allow Origin) issues

Using persistent connections and an ASP.Net Javascript client, I am trying to connect to a sub -domain not the same as the one the page was served from.

ASP.Net Page from webserver sub1.mydomain.com wants to connect to SignalR at sub2.mydomain.com. The same code works fine when connecting within the same sub-domain.

I found another post where cross-domain connections were enabled with:
jQuery.support.cors = true;
but this did not work for me.

How can I connect to SignalR in a second sub-domain using persistent connection and a JavaScript client?

Answer

You need to do one of the following to make it work:

  • Set up $.connection.hub.url = 'http://subdomain.domain.com/signalr';, pointing to your subdomain.
  • Enable cross domain on the server:

    RouteTable.Routes.MapHubs(new HubConfiguration()
    {
      EnableCrossDomain = true
    });
    
Comments