在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.