SignalR中心跨域在Chrome和Firefox中被破坏,长期民意调查在IE11中有效

时间:2014-06-24 02:18:05

标签: cross-domain signalr long-polling signalr-hub

我使用SignalR 2.0.3。我找不到这个版本的SignalR的可靠实例。

在服务器上,我有这个:

app.Map("/signalr", map =>
{
    map.UseCors(CorsOptions.AllowAll);
    var cfg = new HubConfiguration() { EnableJSONP = true };
    cfg.EnableDetailedErrors = true;
    map.RunSignalR(cfg);
});

在客户端,我有这个:

var settings = function() {
    var connectionUrl = window.location.protocol + "//signalr.mydomain.com/signalr";
    var queryString = "Email=JDentler%40dwhomes.com\u0026WindowsAccountName=jdentler";
    return { connectionUrl: connectionUrl, queryString: queryString };
}();

$.connection.hub.url = settings.connectionUrl;
$.connection.hub.qs = settings.queryString;
$.connection.hub.logging = true;
$.connection.hub.start();

这是Chrome 35的输出:

[20:27:50 GMT-0500 (Central Daylight Time)] SignalR: Auto detected cross domain url. jquery.signalR-2.0.3.min.js?_=1403573268960:8

[20:27:50 GMT-0500 (Central Daylight Time)] SignalR: Client subscribed to hub 'calendarhub'. jquery.signalR-2.0.3.min.js?_=1403573268960:8

[20:27:50 GMT-0500 (Central Daylight Time)] SignalR: Client subscribed to hub 'emailhub'. jquery.signalR-2.0.3.min.js?_=1403573268960:8

[20:27:50 GMT-0500 (Central Daylight Time)] SignalR: Client subscribed to hub 'notificationshub'. jquery.signalR-2.0.3.min.js?_=1403573268960:8

[20:27:50 GMT-0500 (Central Daylight Time)] SignalR: Negotiating with 'https://signalr.mydomain.com/signalr/negotiate?Email=JDe…ub%22%7D%2C%7B%22name%22%3A%22notificationshub%22%7D%5D&clientProtocol=1.3'. jquery.signalR-2.0.3.min.js?_=1403573268960:8

[20:27:51 GMT-0500 (Central Daylight Time)] SignalR: Attempting to connect to SSE endpoint 'https://signalr.mydomain.com/signalr/connect?transport=s…2%3A%22emailhub%22%7D%2C%7B%22name%22%3A%22notificationshub%22%7D%5D&tid=2'. jquery.signalR-2.0.3.min.js?_=1403573268960:8

EventSource cannot load https://signalr.mydomain.com/signalr/connect?transport=s…2%3A%22emailhub%22%7D%2C%7B%22name%22%3A%22notificationshub%22%7D%5D&tid=2. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://webapp.mydomain.com' is therefore not allowed access. 764:1

[20:27:52 GMT-0500 (Central Daylight Time)] SignalR: EventSource calling close(). jquery.signalR-2.0.3.min.js?_=1403573268960:8

[20:27:52 GMT-0500 (Central Daylight Time)] SignalR: Opening long polling request to 'https://signalr.mydomain.com/signalr/connect?transport=l…2%3A%22emailhub%22%7D%2C%7B%22name%22%3A%22notificationshub%22%7D%5D&tid=5'. jquery.signalR-2.0.3.min.js?_=1403573268960:8

XMLHttpRequest cannot load https://signalr.mydomain.com/signalr/connect?transport=l…22%7D%2C%7B%22name%22%3A%22notificationshub%22%7D%5D&tid=5&_=1403573269504. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://webapp.mydomain.com' is therefore not allowed access. 764:1
// $.connection.hub.start().fail(...) called
[20:27:53 GMT-0500 (Central Daylight Time)] SignalR: Stopping connection. jquery.signalR-2.0.3.min.js?_=1403573268960:8

[20:27:53 GMT-0500 (Central Daylight Time)] SignalR: Fired ajax abort async = true. jquery.signalR-2.0.3.min.js?_=1403573268960:8

[20:27:53 GMT-0500 (Central Daylight Time)] SignalR: LongPolling failed to connect. jquery.signalR-2.0.3.min.js?_=1403573268960:8

这是我在Firefox 28中的输出:

"[20:46:01 GMT-0500 (Central Standard Time)] SignalR: Auto detected cross domain url." jquery.signalR-2.0.3.min.js:8
"[20:46:01 GMT-0500 (Central Standard Time)] SignalR: Client subscribed to hub 'calendarhub'." jquery.signalR-2.0.3.min.js:8
"[20:46:01 GMT-0500 (Central Standard Time)] SignalR: Client subscribed to hub 'emailhub'." jquery.signalR-2.0.3.min.js:8
"[20:46:01 GMT-0500 (Central Standard Time)] SignalR: Client subscribed to hub 'notificationshub'." jquery.signalR-2.0.3.min.js:8
"[20:46:01 GMT-0500 (Central Standard Time)] SignalR: Negotiating with 'https://signalr.mydomain.com/signalr/negotiate?Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22calendarhub%22%7D%2C%7B%22name%22%3A%22emailhub%22%7D%2C%7B%22name%22%3A%22notificationshub%22%7D%5D&clientProtocol=1.3'." jquery.signalR-2.0.3.min.js:8
"[20:46:01 GMT-0500 (Central Standard Time)] SignalR: Attempting to connect to SSE endpoint 'https://signalr.mydomain.com/signalr/connect?transport=serverSentEvents&connectionToken=IrphkI69y7w99kTtN4TDaKWKKs%2FOrDOPVXdoVoXmXULtpLjfqihin%2BlCrux6H8oSFMHl6a2SMla7ex5nTJi8H1JwykxZoa82nu6Su1xfgcxTwwCfIC3K1R0aUenz5W3h&Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22calendarhub%22%7D%2C%7B%22name%22%3A%22emailhub%22%7D%2C%7B%22name%22%3A%22notificationshub%22%7D%5D&tid=1'." jquery.signalR-2.0.3.min.js:8
"[20:46:02 GMT-0500 (Central Standard Time)] SignalR: EventSource calling close()." jquery.signalR-2.0.3.min.js:8
"[20:46:03 GMT-0500 (Central Standard Time)] SignalR: Opening long polling request to 'https://signalr.mydomain.com/signalr/connect?transport=longPolling&connectionToken=IrphkI69y7w99kTtN4TDaKWKKs%2FOrDOPVXdoVoXmXULtpLjfqihin%2BlCrux6H8oSFMHl6a2SMla7ex5nTJi8H1JwykxZoa82nu6Su1xfgcxTwwCfIC3K1R0aUenz5W3h&Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22calendarhub%22%7D%2C%7B%22name%22%3A%22emailhub%22%7D%2C%7B%22name%22%3A%22notificationshub%22%7D%5D&tid=3'." jquery.signalR-2.0.3.min.js:8
// $.connection.hub.start().fail(...) called
"[20:46:03 GMT-0500 (Central Standard Time)] SignalR: Stopping connection." jquery.signalR-2.0.3.min.js:8
"[20:46:03 GMT-0500 (Central Standard Time)] SignalR: Fired ajax abort async = true." jquery.signalR-2.0.3.min.js:8
"[20:46:03 GMT-0500 (Central Standard Time)] SignalR: LongPolling failed to connect."

这是IE 11的输出,其工作原理为:

[20:51:08 GMT-0500 (Central Daylight Time)] SignalR: Auto detected cross domain url.
[20:51:08 GMT-0500 (Central Daylight Time)] SignalR: Client subscribed to hub 'emailhub'.
[20:51:08 GMT-0500 (Central Daylight Time)] SignalR: Negotiating with 'https://signalr.mydomain.com/signalr/negotiate?Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22emailhub%22%7D%5D&clientProtocol=1.3'.
SEC7118: XMLHttpRequest for https://signalr.mydomain.com/signalr/negotiate?Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22emailhub%22%7D%5D&clientProtocol=1.3&_=1403574667061 required Cross Origin Resource Sharing (CORS).
File: 764
[20:51:09 GMT-0500 (Central Daylight Time)] SignalR: This browser doesn't support SSE.
[20:51:10 GMT-0500 (Central Daylight Time)] SignalR: Opening long polling request to 'https://signalr.mydomain.com:443/signalr/connect?transport=longPolling&connectionToken=ORiixGPQGauG03eZCfeXkHT20wlPmnAgiZI%2Ft5R7CI1NKrrcaeNjbfVWFxrF7ogd7QwUjYu%2FPc9JlFCPiMcaiNVhHbI0CRlucj1egfEnXbDPK4c3WysNbaK%2FgHGorvOk&Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22emailhub%22%7D%5D&tid=0'.
SEC7118: XMLHttpRequest for https://signalr.mydomain.com/signalr/connect?transport=longPolling&connectionToken=ORiixGPQGauG03eZCfeXkHT20wlPmnAgiZI%2Ft5R7CI1NKrrcaeNjbfVWFxrF7ogd7QwUjYu%2FPc9JlFCPiMcaiNVhHbI0CRlucj1egfEnXbDPK4c3WysNbaK%2FgHGorvOk&Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22emailhub%22%7D%5D&tid=0&_=1403574667062 required Cross Origin Resource Sharing (CORS).
File: 764
[20:51:10 GMT-0500 (Central Daylight Time)] SignalR: Long poll complete.
[20:51:10 GMT-0500 (Central Daylight Time)] SignalR: Opening long polling request to 'https://signalr.mydomain.com:443/signalr/poll?transport=longPolling&connectionToken=ORiixGPQGauG03eZCfeXkHT20wlPmnAgiZI%2Ft5R7CI1NKrrcaeNjbfVWFxrF7ogd7QwUjYu%2FPc9JlFCPiMcaiNVhHbI0CRlucj1egfEnXbDPK4c3WysNbaK%2FgHGorvOk&groupsToken=7BwxejWvFqtNj3X0S%2FxPfHRzp3cpmj1x8Zo7XnRiXAOQoURl5UxKnMSyfxkxpFYeL6%2B2RLhX6jqPY8sRIJzrrhXr%2BTLC7Ygk3X28V3%2BJ8yJUjN082h0C15L7hEnutJW3RRXZUjC8QYfOjnoiQ%2BsZDI0D28SYXBVFSArZYiVLHhw%3D&messageId=d-B0017E39-h%2C0%7Cm%2C0%7Cn%2C1%7Co%2C0%7Cl%2C0&Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22emailhub%22%7D%5D&tid=1'.
SEC7118: XMLHttpRequest for https://signalr.mydomain.com/signalr/poll?transport=longPolling&connectionToken=ORiixGPQGauG03eZCfeXkHT20wlPmnAgiZI%2Ft5R7CI1NKrrcaeNjbfVWFxrF7ogd7QwUjYu%2FPc9JlFCPiMcaiNVhHbI0CRlucj1egfEnXbDPK4c3WysNbaK%2FgHGorvOk&groupsToken=7BwxejWvFqtNj3X0S%2FxPfHRzp3cpmj1x8Zo7XnRiXAOQoURl5UxKnMSyfxkxpFYeL6%2B2RLhX6jqPY8sRIJzrrhXr%2BTLC7Ygk3X28V3%2BJ8yJUjN082h0C15L7hEnutJW3RRXZUjC8QYfOjnoiQ%2BsZDI0D28SYXBVFSArZYiVLHhw%3D&messageId=d-B0017E39-h%2C0%7Cm%2C0%7Cn%2C1%7Co%2C0%7Cl%2C0&Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22emailhub%22%7D%5D&tid=1&_=1403574667063 required Cross Origin Resource Sharing (CORS).
File: 764
[20:51:11 GMT-0500 (Central Daylight Time)] SignalR: Long poll complete.
[20:51:11 GMT-0500 (Central Daylight Time)] SignalR: LongPolling connected.
Now connected, connection ID=8a624246-0e75-4dfc-99aa-8540da9e429d
[20:51:11 GMT-0500 (Central Daylight Time)] SignalR: Invoking emailhub.RefreshEmail
SEC7118: XMLHttpRequest for https://signalr.mydomain.com/signalr/send?transport=longPolling&connectionToken=ORiixGPQGauG03eZCfeXkHT20wlPmnAgiZI%2Ft5R7CI1NKrrcaeNjbfVWFxrF7ogd7QwUjYu%2FPc9JlFCPiMcaiNVhHbI0CRlucj1egfEnXbDPK4c3WysNbaK%2FgHGorvOk&Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22emailhub%22%7D%5D required Cross Origin Resource Sharing (CORS).
File: 764
Notifications hub now connected, connection ID=8a624246-0e75-4dfc-99aa-8540da9e429d
Now connected, connection ID=8a624246-0e75-4dfc-99aa-8540da9e429d
[20:51:11 GMT-0500 (Central Daylight Time)] SignalR: Invoking calendarhub.RefreshCalendar
SEC7118: XMLHttpRequest for https://signalr.mydomain.com/signalr/send?transport=longPolling&connectionToken=ORiixGPQGauG03eZCfeXkHT20wlPmnAgiZI%2Ft5R7CI1NKrrcaeNjbfVWFxrF7ogd7QwUjYu%2FPc9JlFCPiMcaiNVhHbI0CRlucj1egfEnXbDPK4c3WysNbaK%2FgHGorvOk&Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22emailhub%22%7D%5D required Cross Origin Resource Sharing (CORS).
File: 764
[20:51:11 GMT-0500 (Central Daylight Time)] SignalR: Opening long polling request to 'https://signalr.mydomain.com:443/signalr/poll?transport=longPolling&connectionToken=ORiixGPQGauG03eZCfeXkHT20wlPmnAgiZI%2Ft5R7CI1NKrrcaeNjbfVWFxrF7ogd7QwUjYu%2FPc9JlFCPiMcaiNVhHbI0CRlucj1egfEnXbDPK4c3WysNbaK%2FgHGorvOk&groupsToken=7BwxejWvFqtNj3X0S%2FxPfHRzp3cpmj1x8Zo7XnRiXAOQoURl5UxKnMSyfxkxpFYeL6%2B2RLhX6jqPY8sRIJzrrhXr%2BTLC7Ygk3X28V3%2BJ8yJUjN082h0C15L7hEnutJW3RRXZUjC8QYfOjnoiQ%2BsZDI0D28SYXBVFSArZYiVLHhw%3D&messageId=d-B0017E39-h%2C0%7Cm%2C0%7Cn%2C2%7Co%2C0%7Cl%2C0&Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22emailhub%22%7D%5D&tid=0'.
SEC7118: XMLHttpRequest for https://signalr.mydomain.com/signalr/poll?transport=longPolling&connectionToken=ORiixGPQGauG03eZCfeXkHT20wlPmnAgiZI%2Ft5R7CI1NKrrcaeNjbfVWFxrF7ogd7QwUjYu%2FPc9JlFCPiMcaiNVhHbI0CRlucj1egfEnXbDPK4c3WysNbaK%2FgHGorvOk&groupsToken=7BwxejWvFqtNj3X0S%2FxPfHRzp3cpmj1x8Zo7XnRiXAOQoURl5UxKnMSyfxkxpFYeL6%2B2RLhX6jqPY8sRIJzrrhXr%2BTLC7Ygk3X28V3%2BJ8yJUjN082h0C15L7hEnutJW3RRXZUjC8QYfOjnoiQ%2BsZDI0D28SYXBVFSArZYiVLHhw%3D&messageId=d-B0017E39-h%2C0%7Cm%2C0%7Cn%2C2%7Co%2C0%7Cl%2C0&Email=JDentler%40dwhomes.com&WindowsAccountName=jdentler&connectionData=%5B%7B%22name%22%3A%22emailhub%22%7D%5D&tid=0&_=1403574667064 required Cross Origin Resource Sharing (CORS).
File: 764

1 个答案:

答案 0 :(得分:0)

事实证明连接请求失败了。这是因为其中一个集线器正在使用炸毁JSON序列化程序的数据回复新连接。由此产生的500响应没有CORS标头,因此行为良好的浏览器忽略了响应。提琴手是你的朋友。 SignalR文档中的错误管道也是如此。