SignalR客户端并不总是根据浏览器和/或网页进行调用

时间:2017-02-06 17:49:05

标签: asp.net google-chrome internet-explorer signalr client-side

我的Web应用程序上的SignalR存在一些不一致的行为。除了几页Web应用程序外,它大部分时间都可以工作,它不会出现在IE 11和Chrome中。有趣的是,它不适用于我有一些Telerik组件的页面(ASP.NET AJAX 2015.3.1104的UI),但我不知道这是否相关。

这是我的hub js文件:

$(document).ready(function () {

var connection = $.hubConnection();
connection.logging = true;
connection.start();

$.connection.eCDHub.logging = true;

//get  hub
var ecdHub = $.connection.eCDHub;

//on starting page => join the ecd hub to receive notifications
$.connection.hub.start().done(function () {
    ecdHub.server.joinECDHub(instId);
    try{
        ecdHub.server.showRequestToAll(null, 0).done(console.log("showRequestToAll"));
    }
    catch (err) {
        console.log("error (" + err+ ")");
    }
    console.log("Connected to notifications (" + instId + ")");
}).fail(function (reason) {
    console.log("SignalR connection failed: " + reason);
});

//on receiving ecd notification
ecdHub.client.showRequest = function (ecd) {
    console.log("eCd notification received");
    if (typeof displayComingRequest == 'function') {
        displayComingRequest(ecd);
    }
    //$("#ecdAlertModel").show();
}

ecdHub.client.showRequestToAll = function (ecd) {
    console.log("notification received for all");
    //displayComingRequest(ecd);
    //$("#ecdAlertModel").show();
}

ecdHub.client.showMessage = function (msg) {
    console.log("Message received: " + msg);
}
});

现在在Firefox中我发现了以下情况:

[12:24:31 GMT-0500 (Eastern Standard Time)] SignalR: Stopping connection.  jquery.signalR-2.2.1.min.js:9:3362
[12:24:31 GMT-0500 (Eastern Standard Time)] SignalR: EventSource calling close().  jquery.signalR-2.2.1.min.js:9:3362
[12:24:31 GMT-0500 (Eastern Standard Time)] SignalR: Fired ajax abort async = false.  jquery.signalR-2.2.1.min.js:9:3362
[12:24:31 GMT-0500 (Eastern Standard Time)] SignalR: Stopping the monitoring of the keep alive.  jquery.signalR-2.2.1.min.js:9:3362
[12:24:33 GMT-0500 (Eastern Standard Time)] SignalR: Window unloading, stopping the connection.  jquery.signalR-2.2.1.min.js:9:3362
[12:24:37 GMT-0500 (Eastern Standard Time)] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5'.  jquery.signalR-2.2.1.min.js:9:3362
[12:24:37 GMT-0500 (Eastern Standard Time)] SignalR: serverSentEvents transport starting.  jquery.signalR-2.2.1.min.js:9:3362
[12:24:37 GMT-0500 (Eastern Standard Time)] SignalR: Attempting to connect to SSE endpoint 'http://192.168.1.251/signalr/connect?transport=serverSentEvents&clientProtocol=1.5&connectionToken=XloZHlV2pNdtdLr%2BeR%2FTDSOKICodsv7MI%2Bj1Zt7rp%2FWs8kOasiDMst9jTYB4scMJsVMEHLxX%2BH0ccG%2BAT9Iunmq2BfT5jzSGCLQALNVw%2FxMW5iPcLFQer2zCWJub5FK8NYzw3Q%3D%3D&tid=10'.  jquery.signalR-2.2.1.min.js:9:3362
[12:24:37 GMT-0500 (Eastern Standard Time)] SignalR: EventSource connected.  jquery.signalR-2.2.1.min.js:9:3362
[12:24:37 GMT-0500 (Eastern Standard Time)] SignalR: serverSentEvents transport connected. Initiating start request.  jquery.signalR-2.2.1.min.js:9:3362
[12:24:37 GMT-0500 (Eastern Standard Time)] SignalR: The start request succeeded. Transitioning to the connected state.  jquery.signalR-2.2.1.min.js:9:3362
[12:24:37 GMT-0500 (Eastern Standard Time)] 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.1.min.js:9:3362
showRequestToAll  hubs.js:25:58
Connected to notifications (101)  hubs.js:30:9
notification received for all

很明显我的客户端方法showRequestToAll()被调用。但是,Chrome就是这样,我看到了:

[12:24:29 GMT-0500 (Eastern Standard Time)] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5'.jquery.signalR-2.2.1.min.js:9 
[12:24:29 GMT-0500 (Eastern Standard Time)] SignalR: serverSentEvents transport starting.jquery.signalR-2.2.1.min.js:9 
[12:24:30 GMT-0500 (Eastern Standard Time)] SignalR: Attempting to connect to SSE endpoint 'http://192.168.1.251/signalr/connect?transport=serverSentEvents&clientProto…nZfR%2F6CVhvHqokc6b6DmNjsrPshxkAfZgCZr1Bcn0P%2FQGz5oe7SRc63F3w%3D%3D&tid=6'.jquery.signalR-2.2.1.min.js:9
[12:24:30 GMT-0500 (Eastern Standard Time)] SignalR: EventSourceconnected.jquery.signalR-2.2.1.min.js:9 
[12:24:30 GMT-0500 (Eastern Standard Time)] SignalR: serverSentEvents transport connected. Initiating start request.jquery.signalR-2.2.1.min.js:9 
[12:24:30 GMT-0500 (Eastern Standard Time)] SignalR: The start request succeeded. Transitioning to the connected state.jquery.signalR-2.2.1.min.js:9 
[12:24:30 GMT-0500 (Eastern Standard Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000 hubs.js:25 
showRequestToAll hubs.js:30 
Connected to notifications (101)

在IE11中:

[12:24:40 GMT-0500 (Eastern Standard Time)] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5'.
[12:24:40 GMT-0500 (Eastern Standard Time)] SignalR: serverSentEvents transport starting.
[12:24:40 GMT-0500 (Eastern Standard Time)] SignalR: This browser doesn't support SSE.
[12:24:40 GMT-0500 (Eastern Standard Time)] SignalR: serverSentEvents transport failed to connect. Attempting to fall back.
[12:24:40 GMT-0500 (Eastern Standard Time)] SignalR: foreverFrame transport starting.
[12:24:40 GMT-0500 (Eastern Standard Time)] SignalR: Binding to iframe's load event.
[12:24:40 GMT-0500 (Eastern Standard Time)] SignalR: foreverFrame transport connected. Initiating start request.
[12:24:40 GMT-0500 (Eastern Standard Time)] SignalR: The start request succeeded. Transitioning to the connected state.
[12:24:40 GMT-0500 (Eastern Standard Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
showRequestToAll
Connected to notifications (101)
[12:24:45 GMT-0500 (Eastern Standard Time)] SignalR: foreverFrame transport timed out when trying to connect.

知道浏览器之间发生了什么?在其他页面上,它可以在IE和Chrome中正常运行。它似乎与FF一起工作。

1 个答案:

答案 0 :(得分:0)

我在没有完全理解它是如何修复它的情况下解决了这个问题。

我使用的是Jquery 3.0.0和SignalR 2.2.1。我降级到JQuery 2.2.4和SignalR 2.0.1 并且它工作正常......如果有人有解释我会很高兴知道它。