问题描述
在SignalR .NET,我们建立了一个连接,下面的客户端和服务器之间:
On SignalR .NET, we establish a connection as below between the client and server:
var connection = new HubConnection("http://mysite/");
接下来,我们订阅的事件,并开始下面的连接:
Next, we subscribe the events and start the connection as below:
connection.Start().Wait();
如果我想建立在客户端和服务器之间的安全连接。我们如何能够做到这一点与当前的特点是什么?
What if I would like to establish a secure connection between the client and server. How can we achieve that with current features?
我注意到,有 System.Net.ICredentials
在 HubConnection
类的属性类型。这是此方式?如果是这样,我们应该如何处理验证在服务器端为我们的集线器?
I noticed that there is a property type of System.Net.ICredentials
on HubConnection
class. Is this the way for this? If so, how should we handle the Auth at the server side for our Hubs?
推荐答案
下面是我有我的设置:
var hubConnection = new HubConnection("http://siteurl");
hubConnection.Credentials = CredentialCache.DefaultNetworkCredentials;
hubProxy = hubConnection.CreateProxy("My.Hub.Namespace");
hubConnection.Start().Wait();
您当然可以传递不同的凭据,我使用DefaultNetworkCredentials
You could of course pass in different credentials, I use DefaultNetworkCredentials
由DefaultNetworkCredentials返回的凭据重新presents在其中运行应用程序的当前安全上下文中的身份验证凭据。对于客户端应用程序,这些通常是运行应用程序的用户的Windows凭证(用户名,密码和域)。对于ASP.NET应用程序,默认网络凭据是登录用户的用户凭证,或者用户正在模拟。
这篇关于.NET客户端和服务器之间SignalR安全连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!