SignalR cross domain not working on browsers other

2019-05-02 01:09发布

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条回答
三岁会撩人
2楼-- · 2019-05-02 01:49

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.

查看更多
登录 后发表回答