我需要使用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);
}
我不知道缺少什么,非常感谢你的帮助。
答案 0 :(得分:0)
好吧,我解决了。我创建了另一个空项目,看到UserManager.GeneratePasswordResetTokenAsync(user.Id)在那里正常工作。我从其他项目中删除了Microsoft.Identity.Core和其他相关软件包并重新添加,现在它的工作就像一个魅力。