azure - 在 Azure SignalR 中配置到 hubContext.Clients.User 的声明映射

标签 azure azure-webjobs azure-signalr

我正在尝试使用 Azure SignalR 向特定用户发送消息,如下所示

await this.hubContext.Clients.User(UserId).SendAsync("NotifyUser", "message");

根据https://learn.microsoft.com/en-us/aspnet/core/signalr/groups?view=aspnetcore-3.0 默认情况下,Signalr 使用 ClaimTypes.NameIdentifier 来识别用户。

我可以更改此默认设置以使用 ClaimTypes.EmailClaim 吗?这是可配置的吗?

最佳答案

对于 .NetCore 应用程序。这种方法有效

public class CustomUserIdentityProvider : IUserIdProvider
        {
        public string GetUserId(HubConnectionContext connection)
        {
            return connection.User.Claims.FirstOrDefault(x => x.Type == Constants.EmailClaim)?.Value;
        }
    }

关于azure - 在 Azure SignalR 中配置到 hubContext.Clients.User 的声明映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58974488/

相关文章:

azure - 默认文档不适用于 Azure Web App

macos - 使用 FreeTDS 连接到 MS SQL (Azure)

azure - 如何在 power shell 中使用 RM 模块获取 Azure 应用程序配置访问 key

c# - 将内部类注入(inject) Azure WebJob 函数

azure - 是否可以将 Azure SignalR 服务与本地 SignalR 结合使用?

Azure Function 到 SignalR(无服务器)再到 Web 应用程序

java - SQL Azure 和 JAVA 不想运行查询

Azure Web 作业始终开启

c# - 部署后无法连接到 Azure SignalR 服务

azure - 如何通过 VS Team Services 自动部署 azure webjob - 发布