Alb*_*orz 5 c# asp.net signalr
我有一个信号服务器2.0服务器应该服务于多个域..因此需要在我的服务器中启用CORS.我将iis7.5用作Web服务器.我在Startup
我的项目方法中启用了CORS,如下所示
public void Configuration(IAppBuilder app)
{
app.Map("/signalr", map =>
{
// Setup the CORS middleware to run before SignalR.
// By default this will allow all origins. You can
// configure the set of origins and/or http verbs by
// providing a cors options with a different policy.
map.UseCors(CorsOptions.AllowAll);
var hubConfiguration = 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
};
// Run the SignalR pipeline. We're not using MapSignalR
// since this branch already runs under the "/signalr"
// path.
map.RunSignalR(hubConfiguration);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码复制并粘贴在本文 http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-javascript-client
我创建了一个localhost项目并尝试连接到signalr服务器.
但我在Firefox中遇到以下错误
阻止跨源请求:http://MyWebSite.com:8082/signalr/negotiate?connectionData=%5B%7B%22name%22%3A%22sahragostarhub%22%7D%5D&clientProtocol=1.3&_=1405622027746
同源策略禁止读取远程资源. 可以通过将资源移动到同一域或启用CORS来解决此问题.谈判
并且
无法加载chrome XMLHttpRequest中的此错误http://MyWebSite.com:8082/signalr/negotiate?connectionData=%5B%7B%22name%22%3A%22sahragostarhub%22%7D%5D&clientProtocol=1.3&_=1405622032883
.请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许访问Origin((我的客户端站点地址)'
我还将以下行添加到我的web.config中
<httpProtocol>
<customHeaders>
<clear />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
Run Code Online (Sandbox Code Playgroud)
这种变化也没用.
<configuration>
<system.webServer>
<modules>
<remove name="WebDAVModule" />
...
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7060 次 |
最近记录: |