SignalR Secure Connection Between .NET Client and The Server

﹥>﹥吖頭↗ 提交于 2020-01-01 01:59:06

问题


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?

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?


回答1:


Here is how I have mine set up:

  var hubConnection = new HubConnection("http://siteurl");
  hubConnection.Credentials = CredentialCache.DefaultNetworkCredentials;
  hubProxy = hubConnection.CreateProxy("My.Hub.Namespace");

  hubConnection.Start().Wait();

You could of course pass in different credentials, I use 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.



来源:https://stackoverflow.com/questions/9722983/signalr-secure-connection-between-net-client-and-the-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!