signalR CORS - IE客户端获得403'禁止访问:JSONP被禁用'

时间:2014-07-21 15:12:38

标签: signalr cors http-status-code-403

我们在启用CORS的情况下实施了SignalR 2.0集线器。 Firefox和Chrome上的Javascript客户端运行正常。 IE 10得到错误403.

任何帮助将不胜感激。 谢谢你和问候。

1 个答案:

答案 0 :(得分:5)

虽然IE 10(但不是IE≤9)应支持CORS,但如果您发现自己需要使用JSONP,则可以在致电MapSignalR时启用它。

启用JSONP可以在发送Cookie /凭据时从任何来源访问您的SignalR应用。使用CORS,您可以限制哪些来源可以访问您的SignalR应用程序,无论是否应使用跨源请求发送cookie /凭证等等。由于JSONP无法配置为与CORS可能实现的更细粒度的安全策略相匹配,因此必须单独启用JSONP:

app.MapSignalR(new HubConfiguration 
{
    // You can enable JSONP by uncommenting line below.
    // JSONP requests are insecure but some older browsers (and some
    // versions of IE) require JSONP to work cross domain
    EnableJSONP = true
});

如果您使用PersistentConnection替换HubConfigurationConnectionConfiguration

您可以详细了解establishing a cross-domain SignalR connection here