加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 23:02:22 所属栏目:asp.Net 来源:网络整理
导读:在SignalR .NET上,我们在客户端和服务器之间建立如下连接: var connection = new HubConnection("http://mysite/"); 接下来,我们订阅事件并开始连接如下: connection.Start().Wait(); 如果我想在客户端和服务器之间建立一个安全的连接怎么办?我们如何用现
在SignalR .NET上,我们在客户端和服务器之间建立如下连接:
var connection = new HubConnection("http://mysite/");

接下来,我们订阅事件并开始连接如下:

connection.Start().Wait();

如果我想在客户端和服务器之间建立一个安全的连接怎么办?我们如何用现在的功能来实现呢?

我注意到在HubConnection类上有一个System.Net.ICredentials的属性类型.这是这样吗?如果是这样,我们应该如何在服务器端处理我们的Hubs的Auth?

解决方法

这是我如何成立:
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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读