SignalR 1.0.1 与 Chrome 的跨域请求 (CORS) [英] SignalR 1.0.1 Cross-domain request (CORS) with Chrome

查看:28
本文介绍了SignalR 1.0.1 与 Chrome 的跨域请求 (CORS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SignalR 1.0.1 和 Chrome(版本 25.0.1364.172)实现跨域调用.因为我的 UI 在一个主机 (localhost:16881) 中,而服务"在另一台主机 (localhost:16901) 中.

I am trying to implement the Cross-domain calls with SignalR 1.0.1 with Chrome (Ver 25.0.1364.172). As I have my UI in one host (localhost:16881) and the 'service' in another host (localhost:16901).

我已经准备好了主题 如何使用 SignalR 使用跨域连接(CORS - Access Control Allow Origin)

 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.

我还在 global.asax 中为 SignalR 1.0.1 的路由映射设置了 HubConfiguration

I also have the HubConfiguration set up for my route mapping in global.asax for SignalR 1.0.1

            RouteTable.Routes.MapHubs(new HubConfiguration()
            {
                EnableCrossDomain = true
            });

在 IE10 和 FF22 中一切正常.但是在 Chrome 中,当 SignalR 尝试握手时,它给了我一个错误.

Everything looks fine in IE10 and FF22. However in Chrome, it gives me an erorr when SignalR trying to do the handshake.

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 一起使用,但它并不真正符合我的要求.请帮忙!

I know I can get it works with Chrome by launching it with --disable-web-security, but it doesn't really fit my requirement. Please help!

推荐答案

这是你需要做的:

  1. 删除 jQuery.support.cors = true
  2. 删除 <add name="Access-Control-Allow-Origin" value="http://localhost:16881"/>

那么它应该可以正常工作.

Then it should work fine.

这篇关于SignalR 1.0.1 与 Chrome 的跨域请求 (CORS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆