2016-06-10 57 views
0

我注意到,在Firefox中,从我的Signal R集线器断开的事件被延迟。我确信这是因为没有收到来自客户端的断开连接事件,而是服务器超时。如果我调试断开连接事件,则stopCalled参数始终为false。信号R Disonnect在Firefox中延迟

我试图从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(); 
}); 

如果我称之为火狐停止方法安慰它立即触发断开事件。

更新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 
+0

有你添加一个断点地看到,断开实际上是被称为?任何与JS控制台相关的东西? – stuartd

+0

是的,我添加了日志消息以确保在JS控制台中调用.stop方法。我可以确认它确实被调用,但是我放在服务器端断开连接事件上的调试点不会被触发,直到经过了很长时间。 – Joe

回答

0

通过删除beforeunload事件绑定来解决问题。我最初添加这个,因为它解决了IE中的类似问题。我现在改变了这个只能在IE中运行。

因此,从问题的JS简直变成: -

$.connection.webHub.start().done();