C# 获取用户';基于其用户ID.net身份的电子邮件地址
我有以下功能,重新生成一个确认电子邮件(完成注册)的情况下,一个过期的链接C# 获取用户';基于其用户ID.net身份的电子邮件地址,c#,asp.net-web-api,asp.net-identity-2,C#,Asp.net Web Api,Asp.net Identity 2,我有以下功能,重新生成一个确认电子邮件(完成注册)的情况下,一个过期的链接 [AllowAnonymous] [HttpGet] [Route("ResendConfirmationEmail")] public async Task<IHttpActionResult> ResendConfirmationEmail(string userId = "") { if (string.IsNullOrWhiteSpace(use
[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();
}
[AllowAnonymous]
[HttpGet]
[发送路线(“重新发送确认邮件”)]
公共异步任务ResendConfirmationMail(字符串userId=”“)
{
if(string.IsNullOrWhiteSpace(userId))
{
AddModelError(“,”需要用户Id”);
返回请求(ModelState);
}
if(userId.GetHashCode()!=null)
{
var code=await UserManager.GenerateEmailConfirmationTokenAsync(userId);
var callbackUrl=newuri(Url.Link(“confirmeailroute”,new{userId,code=code}));
string subject=“请确认您的帐户”;
string body=“请单击此处确认您的帐户:”;
发送电子邮件(????、回拨URL、主题、正文);
}
返回Ok();
}
如何根据用户的
用户ID
从webUsers
表中获取用户的电子邮件?您可以使用UserManager的FindByIdAsync从数据库中获取用户,然后获取电子邮件
var user = await UserManager.FindByIdAsync(userId);
var email = user.Email;
UserManager
有一个名为FindByIdAsync