无法看到方法:UserManager中的SendEmailAsync

时间:2018-03-12 20:38:45

标签: c# asp.net-core-mvc asp.net-core-identity

我正在asp.net中实现密码重置。我使用的是这段代码:

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

从此页面:https://docs.microsoft.com/en-us/aspnet/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity#examine-the-code-in-appstartidentityconfigcs

我收到了错误:

  

'UserManager'不包含的定义   'SendEmailAsync'并且没有扩展方法'SendEmailAsync'接受a   可以找到“UserManager”类型的第一个参数   (您是否缺少using指令或程序集引用?)

我错过了什么?

0 个答案:

没有答案