【发布时间】:2014-11-11 20:39:08
【问题描述】:
我需要使用 Asp.Net Identity 2.1.0 实现忘记密码功能,但是 UserManager.GeneratePasswordResetTokenAsync 挂起并且永远不会返回,我什至尝试了 UserManager.GeneratePasswordResetToken(user.Id) 但无济于事。
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindByNameAsync(model.UserId);
if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
{
ModelState.AddModelError("", "The user either does not exist or is not confirmed.");
return View();
}
//Send an email with this link
string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
return RedirectToAction("ForgotPasswordConfirmation", "Account");
}
// If we got this far, something failed, redisplay form
return View(model);
}
我不知道缺少什么,非常感谢您的帮助。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-5 asp.net-identity asp.net-identity-2