小编ham*_*med的帖子

ASP.NET Core3.1登录后如何获取用户信息

我试图在登录 ASP.NET Core 3.1 后获取用户信息(如姓名、电子邮件、id 等信息)。

这是我在登录操作中的代码

var claims = new List<Claim>()
{
    new Claim(ClaimTypes.NameIdentifier, "NameIdentifire"),
    new Claim(ClaimTypes.Name, "Name"),
    new Claim(ClaimTypes.Email, "Email")
};

var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

var principal = new ClaimsPrincipal(identity);

HttpContext.SignInAsync(principal);
Run Code Online (Sandbox Code Playgroud)

在视图中,我只能通过查看来访问名称@User.Identity.Name。我的问题是:如何获取不同视图中用户的其他信息?

c# claims-based-identity web asp.net-core asp.net-core-3.1

4
推荐指数
1
解决办法
1万
查看次数