locked
signalR: how to send a message to the user once, not to the number of ConnectionId RRS feed

  • Question

  • User-1548796982 posted

    hello

    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

    Thursday, October 19, 2017 3:16 AM

All replies

  • User1771544211 posted

    Hi tadbirgaran,

    The IUserID provide allows users to specify what the userid is based on. By default, there will be an implementation that uses the user's IPrincipal.Identity.Name as the user name. To change this, register your implementation of IUserIdProvider with the global host when your application starts.

    GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => new MyIdProvider());

    For more about this, please take the following link as reference.

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

    Best Regards,

    Jean

    Friday, October 20, 2017 2:42 AM