Using persistent connections and an ASP.NET JavaScript client, I am trying to connect to a sub-domain not the same as the one the page was served from.
ASP.Net Page from webserver sub1.mydomain.com
wants to connect to SignalR at sub2.mydomain.com
. The same code works fine when connecting within the same sub-domain.
I found another post where cross-domain connections were enabled with:
jQuery.support.cors = true;
but this did not work for me.
How can I connect to SignalR in a second sub-domain using persistent connection and a JavaScript client?
What really have solved my issue was:
1 - Add this to global.asax:
2- Set up the web.config of my web project to enable the cross-domain:
3- Then I change the implementation on my html, changing the $.connection() to as follow:
Versions I'm using:
signalR-1.1.0
jquery.signalR-1.1.3.js
dot.net 4.0
You need to do one of the following to make it work:
$.connection.hub.url = 'http://subdomain.domain.com/signalr';
, pointing to your subdomain.Enable cross domain on the server:
If switching from 0.5.1 to 0.5.2, you may have had the following:
Which can be changed to:
In the current version of SignalR, using the now separate CORS package, the API for this has changed to:
See ASP.NET SignalR Hubs API Guide - JavaScript Client.
In Signalr2, you can use the pre-release of Microsoft.Owin.Cors, currently 3.0.0-rc1 as of writing this: Microsoft.Owin.Cors.
More information can be found here:
https://github.com/SignalR/SignalR/wiki/SignalR-JS-Client