使用AzureSignalR向特定用户发送消息

c#

使用Azure SignalR(不是 .Net Core SignalR),是否Clients.Users.SendAsync支持向特定用户发送消息?

[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);
    }
}

如果是,Asp.Net Identity Claims Principal 如何传递给 Azure SignalR?

编辑:2021 年 6 月 18 日

以下回复并未解决这些问题。抱歉,我已经按照文档进行了自定义UserIdBasedProvider等。我想强调一下 -

这个问题与 SignalR 的处理方式有关.Users(<*some-user-id*>).Send()

理想情况下,我们会
.Client(<connection id>).Send()向特定用户发送消息。但是对于这种架构,我们必须自己将 userId 和 connectionId 存储在 DB 等中。

.User(userId).Send()与 .Net Core SignalR 完美配合。所以我相信 SignalR SDK 一定在内存中保存了每个连接 ID 和用户 ID 的映射。

Azure SignalR 是否在内部跟踪 UserId、Connection Id 映射并发送消息?

以上是使用AzureSignalR向特定用户发送消息的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>