Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR Secure Connection Between .NET Client and The Server

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?

like image 385
tugberk Avatar asked Mar 15 '12 15:03

tugberk


People also ask

How secure is SignalR?

SignalR uses encryption and a digital signature to protect the connection token. For each request, the server validates the contents of the token to ensure that the request is coming from the specified user. The username must correspond to the connection id.

Is SignalR two way communication?

SignalR uses Web Sockets and the HTML5 API that helps in bidirectional communication. It also provides an API for server-to-client Remote Procedure Calls (RPC) call, it may be something new for you because most of the time we use a request and response model.

Does SignalR guarantee delivery?

SignalR doesn't guarantee message delivery. Since SignalR doesn't block when you call client methods, you can invoke client methods very quickly as you've discovered.

How many SignalR connections can a server handle?

IIS on client operating systems has a limit of 10 concurrent connections. SignalR's connections are: Transient and frequently re-established. Not disposed immediately when no longer used.


1 Answers

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.

like image 186
Andy May Avatar answered Nov 15 '22 20:11

Andy May