2016-06-10 55 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();