提问人:Greg 提问时间:2/7/2017 更新时间:2/7/2017 访问量:621
SignalR 客户端并不总是根据浏览器和/或网页调用
SignalR client side not always called depending on the browser and / or webpage
问:
我在 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。
答:
0赞
Greg
2/7/2017
#1
我在没有完全理解它如何解决它的情况下解决了这个问题。
我使用的是 Jquery 3.0.0 和 SignalR 2.2.1。我降级到 JQuery 2.2.4 和 SignalR 2.0.1,它工作正常......如果有人有解释,我会很高兴知道。
评论