在 SignalR .NET 上,我们在客户端和服务器之间建立如下连接:
var connection = new HubConnection("http://mysite/");
接下来,我们订阅事件并启动连接,如下所示:
connection.Start().Wait();
如果我想在客户端和服务器之间建立安全连接怎么办?我们如何使用当前的功能实现这一目标?
我注意到有一个属性类型
System.Net.ICredentials
在 HubConnection
类(class)。这是方法吗?如果是这样,我们应该如何在服务器端为我们的集线器处理身份验证?
最佳答案
这是我的设置方式:
var hubConnection = new HubConnection("http://siteurl");
hubConnection.Credentials = CredentialCache.DefaultNetworkCredentials;
hubProxy = hubConnection.CreateProxy("My.Hub.Namespace");
hubConnection.Start().Wait();
您当然可以传入不同的凭据,我使用 DefaultNetworkCredentials
The credentials returned by DefaultNetworkCredentials represents the authentication credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default network credentials are the user credentials of the logged-in user, or the user being impersonated.
关于asp.net - .NET 客户端和服务器之间的 SignalR 安全连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9722983/