问题描述
我正在使用SignalR跨域通信编写Web应用程序.我正在使用最新版本的SignalR 1.0.1.以下是jQuery文档ready事件中的代码:
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');
});
我尝试在Opera,Firefox,Chrome和IE 10上运行该应用程序.我的操作系统是Windows7.它在IE 10上运行良好,在其他浏览器上却无法运行.我将使用开发人员工具的IE模式更改为IE 9,但该模式停止了工作.如果我使用SignalR 0.5.3.版本,则所有浏览器都可以使用相同的代码.
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.
在浏览器的开发人员工具中,我发现以下HTTP状态代码以响应协商请求:"HTTP/1.1 403 Forbidden".
In developer tools of the browser, I found the following HTTP status code in response of negotiation request: "HTTP/1.1 403 Forbidden".
我在这里错过了什么吗?是什么原因导致它在IE 10以外的浏览器上中断?
Am I missing anything here? What is the reason because of which it is breaking on browsers other than IE 10?
推荐答案
确保在您的MapHubs调用中启用跨域.
Ensure that in your MapHubs call that you enable cross domain.
RouteTable.Routes.MapHubs(new HubConfiguration() { EnableCrossDomain = true });
在本地测试跨域时,IE10具有一个有趣的功能,该功能会将任何本地主机端口都视为非跨域.
When testing cross domain locally IE10 has an interesting feature that treats any localhost port as not being cross domain.
这篇关于SignalR跨域不适用于IE10以外的浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!