从ClaimsIdentity获取userId

问题描述 投票:0回答:2

我使用asp.net样板。

我已经对Bearer Token(JWT)进行了身份验证。

在配置文件方法中,我需要获取userId。

这是方法的代码

 [AbpAuthorize]
    [HttpGet]
    public async Task<IActionResult> GetProfileData()
    {
        var identity = (ClaimsIdentity)User.Identity;
    }

现在如果使用identity.,我将只能获得一个名称。如何从中获取userId?

asp.net asp.net-mvc identity aspnetboilerplate
2个回答
0
投票

我找到了答案

只需要像这样重写它


0
投票
public GetClaims (IHttpContextAccessor accessor) // contractor method
{
     var currentUser = accessor.HttpContext.User;
     var userId = currentUser.FindFirst("Id")?.Value;
}
© www.soinside.com 2019 - 2024. All rights reserved.