我正在尝试使用SignalR 1.0.1与Chrome(Ver 25.0.1364.172)实现跨域调用.因为我在一个主机(localhost:16881)中有我的UI,在另一个主机中有'service'(localhost:16901).
我有一切就绪如主题如何使用SignalR的跨域连接(CORS - 访问控制允许来源)
add jQuery.support.cors = true; before opening a connection
set up $.connection.hub.url = 'http://localhost:16901/signalr';, pointing to your subdomain
allow cross-domain requests on server side, by adding the following header description:
<add name="Access-Control-Allow-Origin" value="http://localhost:16881" />
inside system.WebServer/httpProtocol/customHeaders section in Web.config file.
Run Code Online (Sandbox Code Playgroud)
我还为在Signal. 1.0的global.asax中的路由映射设置了HubConfiguration
RouteTable.Routes.MapHubs(new HubConfiguration()
{
EnableCrossDomain = true
});
Run Code Online (Sandbox Code Playgroud)
在IE10和FF22中一切都很好看.但是在Chrome中,当SignalR尝试进行握手时,它给了我一个惊喜.
XMLHttpRequest cannot load http://localhost:16901/signalr/negotiate?_=1363560032589. Origin http://localhost:16881 is not allowed by Access-Control-Allow-Origin.
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过使用--disable-web-security启动它来使用它,但它并不真正符合我的要求.请帮忙!