asp.net - .NET 客户端和服务器之间的 SignalR 安全连接

标签 asp.net signalr

在 SignalR .NET 上,我们在客户端和服务器之间建立如下连接:

var connection = new HubConnection("http://mysite/");

接下来,我们订阅事件并启动连接,如下所示:
connection.Start().Wait();

如果我想在客户端和服务器之间建立安全连接怎么办?我们如何使用当前的功能实现这一目标?

我注意到有一个属性类型 System.Net.ICredentialsHubConnection类(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/

相关文章:

c# - 如何在 ASP.NET MVC 中应用长轮询技术?

asp.net - ASP 调试 - 命中断点然后中止当前请求的执行

asp.net - 发送Excel文件给客户

c# - 我可以通过 ASP.NET 将对象从客户端 javascript 发送到服务器端代码吗?

c# - 在 ASP.NET Core 3 的类库中创建 TagHelper

sockets - 使用SignalR发送消息

asp.net - 如果我想维持 HTTP 和 HTTPS 之间的 session ,我该怎么办 - Asp.Net

asp.net-mvc-4 - 自定义 header 和 Signalr : Asp.Net MVC4 Web Api

javascript - 向特定用户或设备推送通知

c# - Asp.Net SignalR DependencyResolver 不解析集线器