SignalR cross-domain javascript client hub start method fails only when client methods are subscribed. If client methods are not subscribed, hub start is successfully called and the server methods are called successfully.
$.connection.hub.url = 'http://my-cross-domain.com:876/signalr';
$.connection.hub.logging = true;
var chatHub = $.connection.chatHub;
chatHub.client.displayMessage = function (windowID, message) {
alert("test");
};
$.connection.hub.start().done(function () {
alert("Connected");
});
If chatHub.client.displayMessage is not subscribed. It starts and connects well.
But if the client method is subscribed, it doesn't connect and throws the
no-access-control-allow-origin-header-is-present-on-the-requested-resource kind of error.
Failure: While subscribing Client Methods
Success while NOT subscribing Client Methods
UPDATE:
Forgot to mention that I am using CORS for SignalR exactly as Jay pointed out below. Its an MVC Application with a WebAPI controller as well.
Please help!
Response status 500 (Internal Server Error) is about a null reference in the OnConnected method of the Hub. Was able to figure that out using the Fiddler.
On the front end make sure you are NOT setting cors support
On the server, in your startup class, make sure cors is allowed by adding:
Info on Cors/JSONP support can be found at: asp net