【问题标题】:SignalR client side not always called depending on the browser and / or webpageSignalR 客户端并不总是根据浏览器和/或网页调用
【发布时间】:2017-06-23 18:25:38
【问题描述】:

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

这是我的集线器 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。

【问题讨论】:

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


    【解决方案1】:

    我解决了这个问题,但并没有完全理解它是如何解决的。

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

    【讨论】:

      猜你喜欢
      • 2019-06-13
      • 1970-01-01
      • 2014-12-20
      • 2023-01-10
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-21
      相关资源
      最近更新 更多