gpt4 book ai didi

c# - 跨域不适用于 signalr 2.0

转载 作者:太空狗 更新时间:2023-10-29 22:26:20 24 4
gpt4 key购买 nike

我有一个应该为多个域提供服务的 signalr 2.0 服务器。因此需要在我的服务器中启用 CORS。我使用 iis7.5 作为网络服务器。我在项目的 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);
}
}

这段代码是从这篇文章中复制粘贴过来的 http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-javascript-client

我创建了一个本地主机项目并尝试连接到 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” header 。 Origin '(My Client site address)' 因此不允许访问

我还将以下行添加到我的 web.config

 <httpProtocol>
<customHeaders>
<clear />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>

这个改动也是没用的。

最佳答案

尝试 removing WebDAV您配置中的模块(前段时间帮助过我):

<configuration>              
<system.webServer>
<modules>
<remove name="WebDAVModule" />
...

关于c# - 跨域不适用于 signalr 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24811960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com