【问题标题】:UserManager.GeneratePasswordResetTokenAsync Hangs and doesn't return (MVC5)UserManager.GeneratePasswordResetTokenAsync 挂起且不返回 (MVC5)
【发布时间】:2014-11-11 20:39:08
【问题描述】:

我需要使用 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);
    }

我不知道缺少什么,非常感谢您的帮助。

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-5 asp.net-identity asp.net-identity-2


    【解决方案1】:

    好吧,我解决了。我创建了另一个空项目,发现 UserManager.GeneratePasswordResetTokenAsync(user.Id) 在那里工作正常。我从另一个项目中删除了 Microsoft.Identity.Core 和其他相关包并重新添加,现在它的工作就像一个魅力。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-23
      • 1970-01-01
      • 2016-08-03
      • 1970-01-01
      • 1970-01-01
      • 2012-10-06
      • 1970-01-01
      • 2020-06-12
      相关资源
      最近更新 更多