Signalr Disconnect 在 Firefox 中延迟
Signal R Disonnect delayed in Firefox
我注意到在 Firefox 中,来自我的 Signal R 集线器的断开连接事件被延迟了。我很确定这是因为没有收到来自客户端的断开连接事件,而是服务器超时。如果我调试断开连接事件,stopCalled 参数始终为 false。
我试图在 beforeunload 事件上从我的 JavaScript 手动调用停止事件,但这没有任何效果。我读到 Firefox 出于安全原因不允许卸载事件中的同步事件,所以它可能阻止了调用?
CS
public class WebHub : Hub
{
public override Task OnDisconnected(bool stopCalled) { }
}
JS
$.connection.webHub.start().done();
$(window).bind('beforeunload', function() {
$.connection.hub.stop();
});
如果我在 Firefox 控制台中调用停止方法,它会立即触发断开连接事件。
更新 1
启用 SignalR JS 日志记录后,断开连接似乎发生在客户端,只是没有访问服务器。
//navigated page, connection ends
SignalR: Stopping connection." jquery.signalR-2.2.0.js:81:17
SignalR: EventSource calling close()." jquery.signalR-2.2.0.js:81:17
SignalR: Fired ajax abort async = true." jquery.signalR-2.2.0.js:81:17
SignalR: Stopping the monitoring of the keep alive." jquery.signalR-2.2.0.js:81:17
SignalR: Window unloading, stopping the connection." jquery.signalR-2.2.0.js:81:17
//next page load begins
SignalR: Client subscribed to hub 'webhub'." jquery.signalR-2.2.0.js:81:17
SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5 jquery.signalR-2.2.0.js:81:17
SignalR: serverSentEvents transport starting." jquery.signalR-2.2.0.js:81:17
SignalR: Attempting to connect to SSE endpoint 'http://website.co.uk/signalr/connect?transport=serverSentEvents&clientProtocol=1.5 jquery.signalR-2.2.0.js:81:17
SignalR: EventSource connected." jquery.signalR-2.2.0.js:81:17
SignalR: serverSentEvents transport connected. Initiating start request." jquery.signalR-2.2.0.js:81:17
SignalR: The start request succeeded. Transitioning to the connected state." jquery.signalR-2.2.0.js:81:17
SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000" jquery.signalR-2.2.0.js:81:17
问题已通过删除 beforeunload 事件绑定得到解决。我最初添加它是因为它解决了 IE 中的类似问题。我现在在 IE 中将其更改为仅 运行。
所以问题中的 JS 简单地变成了:-
$.connection.webHub.start().done();
我在 FireFox 86 上遇到了同样的问题。花了将近 2-3 天但没有找到任何具体的解决方案。这是一种对我有用的解决方法。当我的浏览器是 firefox 并且它可以工作时,我只是忽略了 $.connection.hub.stop()。
$.connection.webHub.start().done();
$(window).bind('beforeunload', function() {
if (navigator.userAgent.indexOf("Firefox") == -1) {
$.connection.hub.stop();
}
});
我注意到在 Firefox 中,来自我的 Signal R 集线器的断开连接事件被延迟了。我很确定这是因为没有收到来自客户端的断开连接事件,而是服务器超时。如果我调试断开连接事件,stopCalled 参数始终为 false。
我试图在 beforeunload 事件上从我的 JavaScript 手动调用停止事件,但这没有任何效果。我读到 Firefox 出于安全原因不允许卸载事件中的同步事件,所以它可能阻止了调用?
CS
public class WebHub : Hub
{
public override Task OnDisconnected(bool stopCalled) { }
}
JS
$.connection.webHub.start().done();
$(window).bind('beforeunload', function() {
$.connection.hub.stop();
});
如果我在 Firefox 控制台中调用停止方法,它会立即触发断开连接事件。
更新 1
启用 SignalR JS 日志记录后,断开连接似乎发生在客户端,只是没有访问服务器。
//navigated page, connection ends
SignalR: Stopping connection." jquery.signalR-2.2.0.js:81:17
SignalR: EventSource calling close()." jquery.signalR-2.2.0.js:81:17
SignalR: Fired ajax abort async = true." jquery.signalR-2.2.0.js:81:17
SignalR: Stopping the monitoring of the keep alive." jquery.signalR-2.2.0.js:81:17
SignalR: Window unloading, stopping the connection." jquery.signalR-2.2.0.js:81:17
//next page load begins
SignalR: Client subscribed to hub 'webhub'." jquery.signalR-2.2.0.js:81:17
SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5 jquery.signalR-2.2.0.js:81:17
SignalR: serverSentEvents transport starting." jquery.signalR-2.2.0.js:81:17
SignalR: Attempting to connect to SSE endpoint 'http://website.co.uk/signalr/connect?transport=serverSentEvents&clientProtocol=1.5 jquery.signalR-2.2.0.js:81:17
SignalR: EventSource connected." jquery.signalR-2.2.0.js:81:17
SignalR: serverSentEvents transport connected. Initiating start request." jquery.signalR-2.2.0.js:81:17
SignalR: The start request succeeded. Transitioning to the connected state." jquery.signalR-2.2.0.js:81:17
SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000" jquery.signalR-2.2.0.js:81:17
问题已通过删除 beforeunload 事件绑定得到解决。我最初添加它是因为它解决了 IE 中的类似问题。我现在在 IE 中将其更改为仅 运行。
所以问题中的 JS 简单地变成了:-
$.connection.webHub.start().done();
我在 FireFox 86 上遇到了同样的问题。花了将近 2-3 天但没有找到任何具体的解决方案。这是一种对我有用的解决方法。当我的浏览器是 firefox 并且它可以工作时,我只是忽略了 $.connection.hub.stop()。
$.connection.webHub.start().done();
$(window).bind('beforeunload', function() {
if (navigator.userAgent.indexOf("Firefox") == -1) {
$.connection.hub.stop();
}
});