我正在尝试使用 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/