问题
I am writing a web app using SignalR cross domain communication. I am using the latest version of SignalR, 1.0.1. Following is the code in the jQuery's document ready event:
var connection = $.hubConnection(url);
var proxy = connection.createHubProxy(hubName);
connection.start().done(function () {
proxy.invoke('serverMethod');
});
I tried running the application on Opera, Firefox, Chrome and IE 10. My OS is Windows 7. It works well on IE 10 and doesn't work on other browsers. I changed mode of IE using developer tools to IE 9, and it stopped working. The same code works on all browsers if I use SignalR version 0.5.3.
In developer tools of the browser, I found the following HTTP status code in response of negotiation request: "HTTP/1.1 403 Forbidden".
Am I missing anything here? What is the reason because of which it is breaking on browsers other than IE 10?
回答1:
Ensure that in your MapHubs call that you enable cross domain.
RouteTable.Routes.MapHubs(new HubConfiguration() { EnableCrossDomain = true });
When testing cross domain locally IE10 has an interesting feature that treats any localhost port as not being cross domain.
来源:https://stackoverflow.com/questions/15312077/signalr-cross-domain-not-working-on-browsers-other-than-ie10