我正在嘗試允許我的用戶重置密碼,但我無法弄清楚爲什麼code
和callbackUrl
返回false。這是我忘記密碼的方法:爲什麼我生成錯誤,沒有註冊IUserTokenProvider?
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
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");
}
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
string callbackUrl = await ResetPasswordConfirmationTokenAsync(user.Id, "Password Reset");
return RedirectToAction("ForgotPasswordConfirmation", "Account");
}
// If we got this far, something failed, redisplay form
return View(model);
}
然後創建密碼重置任務
private async Task<string> ResetPasswordConfirmationTokenAsync(string userID, string subject)
{
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link:
string code = await UserManager.GeneratePasswordResetTokenAsync(userID);
var callbackUrl = Url.Action("ForgotPassword", "Account", new { userId = userID, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(userID, subject, "Please confirm your account by <a href=\"" + callbackUrl + "\">clicking here</a>");
return callbackUrl;
}
由於這兩個值返回null它生成錯誤沒有IUserTokenProvider已登記。爲什麼user
不爲空時會發生這種情況?
將取消投票,直到標題更改爲更具體。 –
可能的副本 http:// stackoverflow。com/questions/22629936/no-iusertokenprovider-is-registered – PAVITRA