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

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


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});


In the current version of SignalR, using the now separate CORS package, the API for this has changed to:

public void Configuration(IAppBuilder app){    app.Map("/signalr", map =>    {        map.UseCors(CorsOptions.AllowAll);        var hubConfiguration = new HubConfiguration        {        };        map.RunSignalR(hubConfiguration);    });}

See ASP.NET SignalR Hubs API Guide - JavaScript Client.


If switching from 0.5.1 to 0.5.2, you may have had the following:

$.connection.hub.start({ transport: 'longPolling', xdomain: true }, function () {...

Which can be changed to:

$.connection.hub.start({ jsonp: true }, function () {...