After we upgraded our project to SignalR v2 the behaviour of ondisconnect seems changed. When navigating away to another website e.g. google.com, the ondisconnect is called immediately (same goes when closing the tab its running in). But when we navigate to another page in our webproject, the ondisconnect is called much later, supposedly after the timeout runs out. We have validated this behaviour by creating a fresh MVC4 project and the chatHub example to exclude user error on our behalf (tested with google chrome). Our application heavily relies on the ondisconnect being fired when users navigate away from the page (for user cleanup i.e. leaving chatroom).
Could you tell me if this is by design and what options we have to make ondisconnect fire immediately when a user navigates to another page (same as closing a tab)? We have not changed the default timeout/keepalive settings. Added we would like not to have to rely on a method like beforeunload to make this work as it has previously.
Much thanks in advance!
I have posted this to the SignalR team on github, Halter73 responded with a temporary workaround. Please see https://github.com/SignalR/SignalR/issues/2719 for further details.
Adding:
window.onbeforeunload = function (e) {
$.connection.myHub.connection.stop();
};
To our project has fixed the issue.