Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
792 views
in Technique[技术] by (71.8m points)

jquery - SignalR 1.0.1 Cross-domain request (CORS) with Chrome

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).

I have everything in place as in the topic How to use cross-domain connections (CORS - Access Control Allow Origin) with SignalR

 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.

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
            });

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. 

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here's what you need to do:

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

Then it should work fine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...