简体   繁体   English

SignalR 2绑定到声明中的自定义用户ID

[英]SignalR 2 bind to custom userid from claims

According to some posts i decided to try out the binding of the users by custom user id, no the IPrincipal.Identity.Name . 根据一些帖子,我决定尝试通过自定义用户ID(而不是IPrincipal.Identity.Name来绑定用户。

So I've implemented: 所以我实现了:

public class CustomUserIdProvider : IUserIdProvider
{
    public string GetUserId(IRequest request)
    {
        var identity = (ClaimsPrincipal)Thread.CurrentPrincipal;
        string id = identity.Claims.Where(c => c.Type == UserInfoIdClaimType)
                                   .Select(c => c.Value).Single();
        return id;
    }
}

But when this method is called, there are no claims in the identity ... 但是,当调用此方法时,标识中没有声明...

So i can't retrieve on this moment the claims from there? 所以我现在无法从那里检索索赔吗?

Or maybe i should do it differently? 或者也许我应该做不同的事情?

解决的问题,当我在Web配置中执行操作时,似乎我没有正确注册OWIN身份验证!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM