Using Azure SignalR (not .Net Core SignalR), Is Clients.Users.SendAsync supported to send message to specific user?
[Authorize]
public class ChatHub : Hub
{
public async Task OnNewMessage(string userId, string message)
{
await Clients.Users(userId)
//Does Azure SignalR supports sending message to specific user,
// the way .Net Core SignalR does it
.SendAsync("OnNewMessage", userId, message);
}
}
If yes, How Asp.Net Identity Claims Principal gets passed to Azure SignalR?
Edit: 18th June 2021
Responses below are not addressing the concerns. Sorry but I had already followed documentation for customizing UserIdBasedProvider etc. I want to stress out that -
This question is pertaining to how SignalR handles
.Users(<*some-user-id*>).Send();
Ideally we do
.Client(<connection id>).Send() to send message to specific user. But for this architecture we must store userId and connectionId ourselves in DB etc.
.User(userId).Send() works perfectly with .Net Core SignalR. So I believe SignalR SDK must have been keeping map of each connection Id and user Id in memory.
Does Azure SignalR internally keeps track of UserId, Connection Id mapping and sends the message?
You can achieve this by Implementing your customized IUserIdProvider like this and register it as an singleton.
public class UserIdProvider : IUserIdProvider
{
public string GetUserId(HubConnectionContext connection)
{
return connection.User.FindFirst(ClaimConstants.PreferredUserName).Value;
}
}