codezoo codezoo - 1 year ago 81
ASP.NET (C#) Question

How to use cross-domain connections (CORS - Access Control Allow Origin) with SignalR

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
wants to connect to SignalR at
. The same code works fine when connecting within the same sub-domain.

I found another post where cross-domain connections were enabled with: = 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 Source

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

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

    RouteTable.Routes.MapHubs(new HubConfiguration()
      EnableCrossDomain = true
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download