SignalR MVC 5的WebSocket没有有效凭证 [英] SignalR MVC 5 Websocket no valid Credentials

查看:809
本文介绍了SignalR MVC 5的WebSocket没有有效凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在MVC应用程序使用SignalR。它的工作原理很好,但我得到在Chrome控制台下面的错误

i try to use SignalR in MVC Application. It works well but i get the following Error in the Chrome console

 WebSocket connection to 'ws://localhost:18245/signalr/connect?transport=webSockets&clientProtocol=1.4&connectionToken=bNDGLnbSQThqY%2FSjo1bt
8%2FL45Xs22BDs2VcY8O7HIkJdDaUJ4ftIc54av%2BELjr27ekHUiTYWgFMfG6o7RaZwhf
fpXavzWQ1jvkaxGm5rI%2BWtK7j0g1eQC2aOYP366WmRQLXCiYJfsm4EbwX6T8n2Aw
%3D%3D&connectionData=%5B%7B%22name%22%3A%22importerhub%
22%7D%5D&tid=9' failed: HTTP Authentication failed; no valid credentials available 

有趣的是,jQuery的方法,我从控制器通过集线器调用工作正常。

The funny thing is that the jquery method i call from the Controller over the Hub works fine.

jQuery的:

 $(function () {
            // Initialize the connection to the server
            var importerHub = $.connection.importerHub;

            // Preparing a client side function
            // called sendMessage that will be called from the server side
            importerHub.client.sendMessage = function (message) {
                showOrUpdateSuccessMessage(message);
            };
            $.connection.hub.start();
        });

控制器:

var hubContext = GlobalHost.ConnectionManager.GetHubContext<ImporterHub>();
            hubContext.Clients.All.sendMessage("All operations complete");

我使用的.Net V4.5.1,SignalR v2.1.2.0和IIS 8.5与Windows身份验证。

I use .Net v4.5.1, SignalR v2.1.2.0 and IIS 8.5 with Windows Authentication.

如何解决这个问题?

推荐答案

看起来你正在运行到一个Chrome的问题。问题是,浏览器不能正确处理Windows身份验证的WebSockets。

It looks like you are running into a Chrome issue. The problem is that Chrome doesn't properly handle Windows Authentication for WebSockets.

下面是最初的问题提交了一份几年前报告说,Chrome浏览器不支持任何形式的HTTP认证的:

Below is the initial issue submitted a couple years ago reporting that Chrome did not support any form of HTTP authentication:

<一个href=\"https://$c$c.google.com/p/chromium/issues/detail?id=123862\">https://$c$c.google.com/p/chromium/issues/detail?id=123862

这问题已经解决了基本和摘要式身份验证,但不适用于Windows(NTLM /协商)认证。有创造比一个月前少跟踪使用WebSockets Windows身份验证在Chrome支持进步的一个问题:

That issue has been resolved for Basic and Digest authentication, but not for Windows (NTLM/Negotiate) authentication. There was an issue created less than a month ago to track progress on Chrome support for Windows authentication with WebSockets:

<一个href=\"https://$c$c.google.com/p/chromium/issues/detail?id=423609\">https://$c$c.google.com/p/chromium/issues/detail?id=423609

显然,使用Windows身份验证的问题是部分固定在Chrome浏览器开发,但前提是客户已经事先建立一个WebSocket的服务器进行身份验证。

Apparently, the issue with Windows authentication is partially fixed in the Chrome dev channel, but only if the client has already authenticated with the server prior to establishing a WebSocket.

您仍然可以调用的sendMessage 从控制器的原因是因为SignalR自动回退到使用比WebSockets的其他传输(即服务器发送的事件或长轮询)当WebSocket连接失败。 Chrome会妥善SignalR的其他传输处理Windows身份验证。

The reason you can still call sendMessage from your Controller is because SignalR automatically falls back to using a transport other than WebSockets (i.e. server-sent events or long-polling), when the WebSocket connection fails. Chrome will properly handle Windows authentication with SignalR's other transports.

我建议不要改变任何东西。它看起来像Chrome浏览器将最终支持WebSockets的Windows身份验证。

I suggest not changing anything. It looks like Chrome will eventually support Windows authentication for WebSockets.

唯一真正的问题,不是在你的铬控制台错误之外,就是它可能会稍长建立在Chrome中SignalR连接。如果这是一个大问题,可以随时specify什么传输客户端应该尝试使用。所以在Chrome,你只能尝试 serverSentEvents longPolling ,但是当Chrome浏览器的确实的解决这个问题,你会不会使用最好的交通,直到你改变code。

The only real problem, other than the error in your chrome console, is that it might take slightly longer to establish a SignalR connection in Chrome. If that's a big issue, you can always specify what transports the client should attempt using. So on Chrome, you could only try serverSentEvents and longPolling, but then when Chrome does fix the issue, you won't be using the best possible transport until you change your code.

这篇关于SignalR MVC 5的WebSocket没有有效凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆