【发布时间】:2014-10-01 22:05:21
【问题描述】:
我试图在这里使用 Rick Anderson 的示例实现密码重置令牌 http://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity
当我在自己的应用程序中尝试忘记密码控制器的代码时,我没有选择 UserManager.GenerateEmailConfirmationTokenAsync 的选项。有没有人遇到过这个?我正在使用 MVC 5。这可能是 Visual Studio 版本/更新问题吗?我正在使用 VS 2013(版本 12.0.21005.1 REL)。
谢谢,
桑吉夫
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindByNameAsync(model.Email);
if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
{
// Don't reveal that the user does not exist or is not confirmed
return View("ForgotPasswordConfirmation");
}
var 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 here: <a href=\"" + callbackUrl + "\">link</a>");
return View("ForgotPasswordConfirmation");
}
// If we got this far, something failed, redisplay form
return View(model);
}
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-5 forgot-password