我正在尝试使用 SignalR 1.0.1 和 Chrome(版本 25.0.1364.172)实现跨域调用。因为我在一个主机(localhost:16881)中有我的用户界面,而在另一台主机(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.
我还为 SignalR 1.0.1 的 global.asax 中的路由映射设置了 HubConfiguration
RouteTable.Routes.MapHubs(new HubConfiguration()
{
EnableCrossDomain = true
});
在 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.
我知道我可以通过使用 --disable-web-security 启动它来使其与 Chrome 一起使用,但它并不真正符合我的要求。请帮忙!