ASP.NET'FindByNameAsync'返回null吗?

像素保罗

ForgotPassword对基本asp.net身份方法有疑问在单步执行代码var user = await UserManager.FindByNameAsync(model.Email);null,即使我已确认aspnetusers表中存在用户的电子邮件地址,该行也会返回我不确定为什么Visual Studio不允许我进入该FindByNameAsync方法?不知道这是怎么回事?

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");
        }

        var 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 here: <a href=\"" + callbackUrl + "\">link</a>");        
        return View("ForgotPasswordConfirmation");
    }

    // If we got this far, something failed, redisplay form
    return View(model);
}
马蒂亚斯·西塞罗(Matias Cicero)

您正在尝试通过电子邮件地址查找用户。

您应该使用UserManager.FindByEmailAsync

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章