如何使用 Identity 和 ASP.Net Core 获取用户的邮件地址

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

我正在使用 ASP.NET Core 和 ASP.NET Identity。

我正在尝试获取用户的邮件地址(不是当前用户的邮件地址)。

对于当前用户,我没有遇到任何问题,我这样做了并且它正在工作:

private Task<ApplicationUser> GetCurrentUserAsync() => _userManager.GetUserAsync(HttpContext.User);

在我的控制器的方法中:

ApplicationUser curUser = await GetCurrentUserAsync();
string mail = curUser.Email;

它正在工作,但我也想要另一个用户的邮件地址,来自他的标识符。

我怎样才能做到这一点?

asp.net-identity asp.net-core-1.0
1个回答
0
投票

第 1 步:添加声明:

        identity.AddClaim(new Claim("ClaimName",
        model.User.ProfileImageUrl));
        var parincipal = new ClaimsPrincipal(identity);
        await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, parincipal);

第2步:在布局页面中获取用户:

 <img src="@User.FindFirst("ClaimName").Value"  alt="" />

此示例从 AspNetUsers 表获取用户个人资料图像,以使用声明在布局页面中显示图像

© www.soinside.com 2019 - 2024. All rights reserved.