简体   繁体   中英

SignalR - Private Messaging-Userid

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM