0
votes

I'm rather new to SignalR and I've hit a wall: I currently have an ASP.NET MVC app running on one server (users coming in and logging into the app with their credentials) and a SignalR hub which is running inside a Windows Service hosted on a different machine using OWIN and self hosting. I've managed to get my web app and SignalR hub to work together, client is connecting to the hub and is able to send/receive data to/from SignalR.

However, I would like my web app to always connect to SignalR for a specific user using the same connectionId - which I would prefer to be the userId (or something based on this). Since SignalR is self hosted, in the Context object available in the Hub implementation I don't have access to the User from my MVC app. As far as I saw I can't set the connectionId from the client side (jQuery), but correct me if I'm wrong... so any ideas or suggestions on how I could achieve the desired behavior would be much appreciated!

1

1 Answers

2
votes

It is not possible to configure custom connectionId's. It is however possible to address clients by userId and even provide your own IUserIdProvider. Simply use Clients.User(userId).myMethod() instead of Clients.Client(connectionId).myMethod().

If you don't provide your own IUserIdProvider, the default userId for a given client will be the value of Context.User.Identity.Name when said client invokes a Hub method.