You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 22:35:20