Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

signalR interrupted while the page was loading error when navigating from a page

When navigating away from a page that has signalR connection/connected hub I get the following error message.

The connection to "http://localhost:53604/signalr/signalr/connect?transport=serverSentEvents&connectionId=0b308c0d-2122-4e60-a9fa-f6e3f3eb1f4e&connectionData=%5B%7B%22name%22%3A%22packageactionstatus%20%22%7D%5D&tid=9" was interrupted while the page was loading.

I do understand that the connection was lost (which is Ok) due to navigating away from the page but is there a safe way to stop the connection before navigating away from the current page?

like image 385
ShaneKm Avatar asked Nov 13 '12 08:11

ShaneKm


2 Answers

You can close the connection onunload:

$.connection.hub.stop();

Though I'm not sure why do you care of this error.

like image 66
gdoron is supporting Monica Avatar answered Sep 28 '22 06:09

gdoron is supporting Monica


To do this properly you want to trap the onbeforeunload event, and you want to do it like so:

window.onbeforeunload = function () {
    $.connection.hub.stop();
};

Fixed the problem for me with firefox.

like image 41
Rocklan Avatar answered Sep 28 '22 06:09

Rocklan