使用Internet Explorer 11时,客户端无法连接到本地自托管的SignalR服务器



我们有一个自托管的SignalR服务器(Windows应用程序),在http://localhost:8080本地运行。我们还有一个单独的网站,其中一个页面通过集线器连接到自托管的SignalR服务器。当网站托管在我的本地机器上时,客户端可以很好地连接到SignalR服务器。一旦我将网站部署到Azure服务器,客户端页面将不再连接到本地SignalR服务器。

我们使用的是SignalR 2.1.1版本和JQuery 2.1.1。

奇怪的是,这个问题只发生在IE(我们使用的是版本11)。当客户端网站托管在本地时,IE可以正常工作,但是当网站托管在云上时,IE就不能工作了。当使用Chrome(最新版本)时,无论网站托管在哪里,客户端都将连接。

起初我以为这只是一个CORS问题,所以我研究了我能找到的所有东西,并尝试了这里以及其他地方推荐的所有东西,但无济于事。

这是IE控制台日志(来自$.connection.hub)。对于客户端页面托管在Azure中的场景(客户端无法连接):

HTML1300: Navigation occurred.
File: comlinktestharness.html
[16:18:03 GMT-0500 (Central Daylight Time)] SignalR: Auto detected cross domain url.
[16:18:03 GMT-0500 (Central Daylight Time)] SignalR: Client subscribed to hub 'comlinkhub'.
[16:18:03 GMT-0500 (Central Daylight Time)] SignalR: Negotiating with 'http://localhost:8080/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22comlinkhub%22%7D%5D'.
[16:18:03 GMT-0500 (Central Daylight Time)] SignalR: Stopping connection.

这里是相应的Fiddler trace:

GET http://mysite.azurewebsites.net/testharness/comlinktestharness.html
200 OK (text/html)
GET http://mysite.azurewebsites.net/Scripts/jquery-2.1.1.min.js
200 OK (application/x-javascript)
GET http://mysite.azurewebsites.net/Scripts/jquery.signalR-2.1.1.min.js
200 OK (application/x-javascript)
GET http://localhost:8080/signalr/hubs
200 OK (application/javascript)

如您所见,IE客户端尝试协商,但连接被停止。没有错误返回给客户端,也没有错误在Hub管道中抛出(我已经在SignalR服务器上启用了错误记录和跟踪)。

下面是工作场景的IE控制台日志(当客户端网站托管在本地时):

[16:51:12 GMT-0500 (Central Daylight Time)] SignalR: Auto detected cross domain url.
[16:51:12 GMT-0500 (Central Daylight Time)] SignalR: Client subscribed to hub 'comlinkhub'.
[16:51:12 GMT-0500 (Central Daylight Time)] SignalR: Negotiating with 'http://localhost:8080/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22comlinkhub%22%7D%5D'.
[16:51:12 GMT-0500 (Central Daylight Time)] SignalR: Connecting to websocket endpoint 'ws://localhost:8080/signalr/connect?transport=webSockets&clientProtocol=1.4&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAAAL6z3nwT%2FfU%2BsVLkmYFEbFAAAAAACAAAAAAAQZgAAAAEAACAAAABBbno6Hw%2FRMgCwrkTmBB0yFdPD1pbLdlxqybV%2FIaio8QAAAAAOgAAAAAIAACAAAAC%2BS5tItVzar1XbLz2znCKXNaCnrW%2FdOYCPjFFV0HcUgDAAAACwab%2F5nGEG6iOLb2yGa8wXdQw%2Bl7T1dF60mArUv9GveCf7PpDJ6eHjlrPh3ePuRKdAAAAAkOqGRkWggu1zFBjUOXjHfW0St8EJ3EL%2B4lKNhLjFMnzh5ER48ZkaF42XN0HN3idX8834Xbp5RlFJy6ljE0npuA%3D%3D&connectionData=%5B%7B%22name%22%3A%22comlinkhub%22%7D%5D&tid=10'.
[16:51:12 GMT-0500 (Central Daylight Time)] SignalR: Websocket opened.
[16:51:12 GMT-0500 (Central Daylight Time)] SignalR: webSockets transport selected. Initiating start request.
[16:51:12 GMT-0500 (Central Daylight Time)] SignalR: The start request succeeded. Transitioning to the connected state.
[16:51:12 GMT-0500 (Central Daylight Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332 and a connection lost timeout of 20000.

下面是成功场景对应的Fiddler跟踪:

POST http://localhost:8080/signalr/abort?transport=webSockets&clientProtocol=1.4&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAAAL6z3nwT%2FfU%2BsVLkmYFEbFAAAAAACAAAAAAAQZgAAAAEAACAAAADwU6H8SJ5n8MePxQmgfQrUbS55oh8ENsX0QPGOufSSUQAAAAAOgAAAAAIAACAAAAC6hHjHaQhxYWGrx5US2q%2FWVIcB34cfcHf0xEX1mY6AqzAAAABatf%2ByMhKKTc%2FLtakiTcuw5XIeAGczBVKQTcXHcRxNJ5my4DR9ec%2BkyBhh0us6Ql5AAAAAkZ18xiOkPzVingDTOcGOXVZziJcSUXfTYn03zIUnbuYAPj8TS5LD3LZ9s9eT4vqNwRFrQ2orA8k3dTtw5NJK%2BQ%3D%3D&connectionData=%5B%7B%22name%22%3A%22comlinkhub%22%7D%5D
200 OK ()
GET http://localhost:54792/TestHarness/ComLinkTestHarness.html
200 OK (text/html)
GET http://localhost:54792/Scripts/jquery-2.1.1.min.js
200 OK (application/javascript)
GET http://localhost:8080/signalr/hubs
200 OK (application/javascript)
GET http://localhost:54792/Scripts/jquery.signalR-2.1.1.min.js
200 OK (application/javascript)
GET http://localhost:54792/favicon.ico
200 OK (image/x-icon)
GET http://localhost:8080/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22comlinkhub%22%7D%5D&_=1407448272112
200 OK (application/json)
CONNECT http://localhost:8080
200 Connection Established ()
GET http://localhost:8080/signalr/connect?transport=webSockets&clientProtocol=1.4&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAAAL6z3nwT%2FfU%2BsVLkmYFEbFAAAAAACAAAAAAAQZgAAAAEAACAAAABBbno6Hw%2FRMgCwrkTmBB0yFdPD1pbLdlxqybV%2FIaio8QAAAAAOgAAAAAIAACAAAAC%2BS5tItVzar1XbLz2znCKXNaCnrW%2FdOYCPjFFV0HcUgDAAAACwab%2F5nGEG6iOLb2yGa8wXdQw%2Bl7T1dF60mArUv9GveCf7PpDJ6eHjlrPh3ePuRKdAAAAAkOqGRkWggu1zFBjUOXjHfW0St8EJ3EL%2B4lKNhLjFMnzh5ER48ZkaF42XN0HN3idX8834Xbp5RlFJy6ljE0npuA%3D%3D&connectionData=%5B%7B%22name%22%3A%22comlinkhub%22%7D%5D&tid=10
101 Switching Protocols ()
GET http://localhost:8080/signalr/start?transport=webSockets&clientProtocol=1.4&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAAAL6z3nwT%2FfU%2BsVLkmYFEbFAAAAAACAAAAAAAQZgAAAAEAACAAAABBbno6Hw%2FRMgCwrkTmBB0yFdPD1pbLdlxqybV%2FIaio8QAAAAAOgAAAAAIAACAAAAC%2BS5tItVzar1XbLz2znCKXNaCnrW%2FdOYCPjFFV0HcUgDAAAACwab%2F5nGEG6iOLb2yGa8wXdQw%2Bl7T1dF60mArUv9GveCf7PpDJ6eHjlrPh3ePuRKdAAAAAkOqGRkWggu1zFBjUOXjHfW0St8EJ3EL%2B4lKNhLjFMnzh5ER48ZkaF42XN0HN3idX8834Xbp5RlFJy6ljE0npuA%3D%3D&connectionData=%5B%7B%22name%22%3A%22comlinkhub%22%7D%5D&_=1407448272113
200 OK (application/json)

正如我之前提到的,这只是IE中的一个问题…无论客户端网站托管在哪里,Chrome都可以工作。

以下是SignalR服务器的Startup和Hub代码:
public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule());
        app.Map("/signalr", map =>
        {
            map.UseCors(CorsOptions.AllowAll);
            var hubConfiguration = new HubConfiguration
            {
            };
            map.RunSignalR(hubConfiguration);
        });
    }
}
public class ComLinkHub : Hub
{
    public void SendEid(string eid)
    {
        Clients.All.eidChanged(eid);
    }
}

最后,这是客户端网页的代码:

$(function () {
    $.connection.hub.url = "http://localhost:8080/signalr";
    var chat = $.connection.comLinkHub;
    chat.client.eidChanged = function (message) {
        // Handle server message
    };
    $.connection.hub.logging = true;
    $.connection.hub.start().done(function () {
        // Do something
    });
});

谁能告诉我为什么这在Chrome中工作,而不是在IE 11?这个问题我已经绞尽脑汁了,但还是想不出解决办法。任何帮助将不胜感激!

谢谢

在进一步研究之后,我看到了这篇文章,它引导我找到了一个解决方案。修复方法是选择

设置->Internet选项->安全->本地intranet->站点

并取消勾选"包括所有未在其他区域列出的本地(intranet)站点"。

相关内容

  • 没有找到相关文章

最新更新