I'm hosting my signalr hub on a separate domain and making cross domain connection to hub from my main application. When a user logs into the main application, signalr connection is established. Now, the problem I'm having is how to identify the connected user inside the hub.
If my Hub was within the main application then I could use the Context.User of the logged in user and maintain a dictionary and update them on Connect and Disconnect events.
But being a cross-domain connection, I don't have the Context.User and no way for me to know to whom that connection ID belongs to. I'm lost here.
What am I missing here?
You should keep users credentials and connections ids yourself. You should define
List<ClientsEntity>
or something like that. Then overrideonConnected
andonDisconnected
methods. Client has to send querystring for connecting to your Hub as Lars said.for example clients send to you like this
$.connection.hub.qs = { 'token' : 'id' };
In the Hub Class:
You could assign a unique connection token to the user once they log in; then make the client send that in the query string: