Take the 2-minute tour ×

Trying to call signalR from another domain, and keep on getting this error:

XMLHttpRequest cannot load localhost:62150/signalr/negotiate?_=1362242757692. Origin localhost:4982 is not allowed by Access-Control-Allow-Origin.

This is the code I'm trying to run:

$(function () {
    jQuery.support.cors = true;
    $.connection.hub.url = 'http://localhost:62150/signalr';
        .done(function () { alert("Now connected!"); })

jquery and jquery.signalr.js are loaded, localhost:62150/signalr/hubs responds with JS, localhost:62150/signalr/hubs/negotiate?_=1362243021215 returns JSON if I run this in browser - so its not a missing script or invalid path issue.

What I've tried:

And combinations of all of the above.

Anyone has any idea what else I can try ?

The serving app is a combination of MVC and WebAPI (don't think it makes any difference). If I'm trying that code from same domain - it works.

share|improve this question
What browser are you using to test this? Does it support CORS? –  Darin Dimitrov Mar 2 '13 at 17:05
Chrome. I can do a cross-domain calls to Web Api via ajax, so yeah. –  Eugene Mar 2 '13 at 18:17
add comment

2 Answers

up vote 4 down vote accepted

If you are using 1.0 or higher have you enabled cross domain on the server? (it's disabled by default now)

RouteTable.Routes.MapHubs(new HubConfiguration { EnableCrossDomain = true });
share|improve this answer
For christ sake... I hate when ppl introduce breaking changes, and don't mention them.. Thats like 2 hours I wasted. Thanks! –  Eugene Mar 2 '13 at 19:04
previous versions were pre-release, and SignalR 1.0 is the first RTM one, so that's not a breaking change ;-) –  Filip W Mar 2 '13 at 19:43
FWIW this change is prominently mentioned in the release notes under "1.0 Breaking Changes". github.com/SignalR/SignalR/blob/master/ReleaseNotes.md is the best place to look for changes in each release. –  halter73 Mar 3 '13 at 8:17
I got the error above even I have this line of code. If I use RouteTable.Routes.MapHubs() instead, I will get 304. My code is working with IE10 and FF 20, but not with Chrome 25.0.1364.172. Any idea? –  Adamy Mar 15 '13 at 5:02
I get this output: ...\Global.asax.cs(17,64,17,81): error CS0117: 'Microsoft.AspNet.SignalR.HubConfiguration' does not contain a definition for 'EnableCrossDomain' ...\Global.asax.cs(17,13,17,91): error CS0619: 'System.Web.Routing.SignalRRouteExtensions.MapHubs(System.Web.Routing.RouteColle‌​ction, Microsoft.AspNet.SignalR.HubConfiguration)' is obsolete: 'Use IAppBuilder.MapSignalR in an Owin Startup class. See go.microsoft.com/fwlink/?LinkId=320578 for more details.' –  Akira Yamamoto Feb 3 at 14:21
add comment

After wasting a couple of hours I think it's good to share my experience:

  1. DO NOT add Access-Control-Allow-Origin to your web.config (yes it never sais to add it, but when trying things this is literally the first I did and left it there after a simple jquery cross-domain access test)

  2. RouteTable.Routes.MapHubs( new HubConfiguration() { EnableCrossDomain = true } ); works just fine for classes inheriting Hub

  3. RouteTable.Routes.MapConnection<MyConnection>( "foo", "/foo", new ConnectionConfiguration { EnableCrossDomain = true } ); this works just fine too for classes inheriting PersistentConnection

share|improve this answer
add comment

Your Answer


