1
我已經更新身份在我的項目2個版本,並在AccountController
ForgotPassword
動作我在這一行收到No IUserTokenProvider is registered error
:沒有IUserTokenProvider登記錯誤更新身份後1〜2
string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
然後我實現IUserTokenProvider
接口基礎在this和IdentityConfig
我使用:
public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
//other code
manager.UserTokenProvider = new MyUserTokenProvider<ApplicationUser>();
return manager;
}
,但同樣的錯誤再次發生。 然後我初始化manager.UserTokenProvider
在ForgotPassword
行動和每件事情都很好。
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindByEmailAsync(model.Email);
if (user == null)
{
return View("error message");
}
UserManager.UserTokenProvider = new MyUserTokenProvider<ApplicationUser>();
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);
}
我不知道是什麼問題。 任何人都可以幫助我嗎? 感謝先進。
MyUserTokenProvider的外觀如何? – Ovis