If you want to send a message to a specific user in SignalR, the easiest way is to use form authentication. You can also use your own session with form authentication. Immediately after creating the session code, enter this code.
FormsAuthentication.SetAuthCookie(username.Trim(), false);
Then in signalR you can use this line to send a message to this user:
var username = Context.User.Identity.Name; context.Clients.User(username).updateMessages(message);
EDIT:
For your question, pass the username to this method (receiver username) and press the message to this user. Then you do not need to specify userForId, because you already have a sender username with the name "var username = Context.User.Identity.Name;". Also, this method will simply click on the recipient username method. If you also want to receive the message to the sender, you will need the user "Caller", and you need to write a new function to receive caller messages in javascript. I hope this is clear to you.
public void Send(string username, string message) { context.Clients.Caller.updateMessagesCaller(message); context.Clients.User(username).updateMessages(message); }
This message will only indicate the username. And my recommendation uses the implementation of FormAuthentication throughout the project. Thanks.
source share