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

查看:30
本文介绍了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");

我使用带有 Windows 身份验证的 .Net v4.5.1、SignalR v2.1.2.0 和 IIS 8.5.

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

我该如何解决这个错误?

How can I fix this error?

推荐答案

您似乎遇到了 Chrome 问题.问题在于 Chrome 无法正确处理 WebSocket 的 Windows 身份验证.

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:

https://code.google.com/p/chromium/问题/详细信息?id=123862

该问题已针对 Basic 和 Digest 身份验证解决,但不适用于 Windows (NTLM/Negotiate) 身份验证.不到一个月前创建了一个问题,用于跟踪 Chrome 支持使用 WebSockets 进行 Windows 身份验证的进度:

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:

https://code.google.com/p/chromium/问题/详细信息?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 会在 WebSocket 连接失败时自动回退到使用 WebSockets 以外的传输(即服务器发送的事件或长轮询).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 控制台中的错误之外,唯一真正的问题是在 Chrome 中建立 SignalR 连接可能需要稍长的时间.如果这是一个大问题,您可以随时指定客户端应该尝试使用什么传输.因此,在 Chrome 上,您只能尝试 serverSentEventslongPolling,但是当 Chrome 确实解决问题时,您将不会使用最好的可能的运输,直到您更改代码.

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天全站免登陆