我试图在我的WebApi控制器中创建一个动作来发送带有passwors重置链接的电子邮件。但是当电子邮件到达时,链接网址是" http://Account/ResetPassword/ ........"
请注意,de link中缺少网站网址。我需要像" http://www.domain.com/account/resetpassword/ ........."
这样的东西这是我的代码。谢谢!
[System.Web.Http.AllowAnonymous]
[System.Web.Http.HttpGet]
[System.Web.Http.Route("ForgotPassword")]
public async Task<IHttpActionResult> ForgotPassword(string email)
{
if (string.IsNullOrWhiteSpace(email))
{
ModelState.AddModelError("", "Email is required");
return BadRequest(ModelState);
}
var user = await AppUserManager.FindByNameAsync(email);
if (user != null)
{
string code = await AppUserManager.GeneratePasswordResetTokenAsync(user.Id);
var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
urlHelper.Action("ResetPassword", "Account", new RouteValueDictionary(new { userId = user.Id, code }), protocol: Request.RequestUri.Scheme);
await AppUserManager.SendEmailAsync(user.Id, "Redefinir Senha", "Redefina sua senha clicando <a href=\"" + callbackUrl + "\">aqui</a>");
return Ok();
}
return NotFound();
}