Can I get SignalR to not disconnect itself when settings window location?

瘦欲@ 提交于 2019-12-11 06:24:09

问题


I am writing a simple page that listens to SignalR events that once detected will perform an ajax request to a web service on our servers.

Once that ajax request is complete, a url is returned with a custom URI scheme that once reirected to, will open up a custom program installed on the client machine without navigating away from the main page. This is achieved by calling window.location = url; in the success callback of the ajax request.

This method works find on the other areas of our website that we are using this, making multiple ajax requests and redirecting in the callback work as it should by sending commands to our program without affecting the main page.

The new page I am creating however uses SignalR to decide when to make these same ajax requests but it is disconnecting itself upon the first redirect. I find the following message in the javascript console which I understand is quite normal to see when a page is unloaded but in the case of my scenario, the calling page is never actually unloaded: The connection to ... was interrupted while the page was loading.

I am looking for a way to stop SignalR from disconnecting itself on the redirect as this causes further redirects to fail until SignalR re-establishes the connection.


回答1:


SignalR tries to gracefully stop any ongoing connections when the user navigates away from the page. SignalR does this by binding to window unload events using jQuery. Typically this is done using $(window).bind("unload", //..., but in Firefox $(window).bind("beforeunload", //... is also used.

Assuming you don't attach to either of these events yourself, you can prevent this behavior by unbinding the unload and beforeunload event handlers bound by SignalR using jQuery:

$(window).unbind("unload");
$(window).unbind("beforeunload");


来源:https://stackoverflow.com/questions/23560929/can-i-get-signalr-to-not-disconnect-itself-when-settings-window-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!