0

In the signalr, for each tag that opens, the ConnectionId registers for the user.

I use the following code to send messages to users. 1 2

hubContext.Clients.Clients (user.ConnectionIds.ToLi st ()); receiveNotification (message, userID, link);

The problem I have is that I want to send a message to the user once, not to the number of ConnectionId.

How can I find one of its active ConnectionIds and just send that message?

Is there a better way?

I also worked on this link

https://stackoverflow.com/questions/...ovider-new-2-0

But because of I do not use request.User.Identity.Name, this method does not work. I'm using my user id. I'm reading the table. value of request.User.Identity.Name in my app is empty because i'm reading user information from table in database

Thanks for your advice

1 Answers1

0

You can retain connection and user information in a Map that is stored in memory.

private readonly Dictionary<T, HashSet<string>> _connections =
            new Dictionary<T, HashSet<string>>();

You can find the fulle example here :

https://learn.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/mapping-users-to-connections

Quentin Roger
  • 6,410
  • 2
  • 23
  • 36