根据userID .net身份获取用户的电子邮件地址
本文关键字:用户 电子邮件地址 获取 身份 userID net 根据 | 更新日期: 2023-09-27 18:12:24
我有以下功能,重新生成确认电子邮件(完成注册)的情况下,过期的链接。
[AllowAnonymous]
[HttpGet]
[Route("ResendConfirmationEmail")]
public async Task<IHttpActionResult> ResendConfirmationEmail(string userId = "")
{
if (string.IsNullOrWhiteSpace(userId))
{
ModelState.AddModelError("", "User Id is required");
return BadRequest(ModelState);
}
if (userId.GetHashCode() != null)
{
var code = await UserManager.GenerateEmailConfirmationTokenAsync(userId);
var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId, code = code }));
string subject = "Please confirm your account";
string body = "Please confirm your account by clicking this : <a href='"" + callbackUrl + "'">link</a>";
SendEmail(?????, callbackUrl, subject, body);
}
return Ok();
}
如何根据用户的userid
从webUsers
表中获取用户的电子邮件?
您可以使用UserManager的FindByIdAsync从数据库中获取用户,然后获取电子邮件
var user = await UserManager.FindByIdAsync(userId);
var email = user.Email;