Asp.Net MVC后台重置密码报错:SetPasswordHashAsync调用异常
Asp.Net MVC管理员重置用户密码时SetPasswordHashAsync报错问题
在Asp.Net MVC项目中实现管理员无需邮件链接重置用户密码功能,参考Stack Overflow上的「MVC Admin reset of User Password」方案编写代码,但执行await store.SetPasswordHashAsync(cUser, hashedNewPassword);代码行时出现错误。
控制器代码
// // POST: /Account/ResetPassword [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> ResetPassword(ResetPasswordViewModel model) { ApplicationDbContext context = new ApplicationDbContext(); UserStore<ApplicationUser> store = new UserStore<ApplicationUser>(context); UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser> (store); string userId = model.Id; string newPassword = model.NewPassword; string hashedNewPassword = UserManager.PasswordHasher.HashPassword(newPassword); ApplicationUser cUser = await store.FindByIdAsync(userId); await store.SetPasswordHashAsync(cUser, hashedNewPassword); await store.UpdateAsync(cUser); return RedirectToAction("Index"); }
附带错误截图及重置密码视图代码截图。
内容的提问来源于stack exchange,提问作者Shiela Mae Rafols Malaque
相关产品推荐
相关产品推荐

