SignalR OnConnected and OnDisconnected not firing SignalR OnConnected and OnDisconnected not firing asp.net asp.net

SignalR OnConnected and OnDisconnected not firing


Your client handlers should probably look like this:

$.connection.onlineHub.client.connected = function(){...}


It also turns out that on a script you need to define at least one client callback for events to be raised on the hub. Be careful with this when expected OnConnected and OnDisconnected to be called.


Figured it out. I was calling the methods on the server object rather than the client:

$.connection.onlineHub.server.connected = function (id, date) {        $("#results").append("connected: " + id + " : " + date + "</br>");    };    $.connection.onlineHub.server.disconnected = function (id, date) {        $("#results").append(("connected: " + id + " : " + date + "</br>");    };

should be

$.connection.onlineHub.client.connected = function (id, date) {        $("#results").append("connected: " + id + " : " + date + "</br>");    };    $.connection.onlineHub.client.disconnected = function (id, date) {        $("#results").append(("connected: " + id + " : " + date + "</br>");    };

So it looks like if signalR hasn't got anything defined for the task within the OnDisconnected or OnConnected, then they don't get fired. Which makes sense.