I am working on Signal-R private messaging. I tried to use sessions but didn't do. I want to use user-ids from database instead of context.ConnectionId. How can i do this?
Asked
Active
Viewed 680 times
0
-
you can pass a userId (or any sort of information) from the client on hub connection as a parameter, and then estabilish a 1:1 group in your hub. You can then execute hub methods which target that group (with one ID) which will essentially accomplish this – scniro Jan 10 '15 at 19:28
-
could you give me some example? – dave Jan 10 '15 at 19:42
1 Answers
0
I suggest you use an IUserIdProvider
. The default one generates user names from the client's IPrincipal.Identity.Name
, but you can provide your own:
http://www.asp.net/signalr/overview/guide-to-the-api/mapping-users-to-connections#IUserIdProvider
This allows you to send messages using .User(userName)
instead of .Client(connectionId)
.
The article I linked to also provides a few alternatives such as single-user groups for messaging users without using their connection ID.

halter73
- 15,059
- 3
- 49
- 60