mvc标识 - SignInManager.PasswordSignInAsync返回null

时间:2017-03-04 21:02:10

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

更新

通过添加

解决了这个问题
ConfigureAuth(app);

到Startup.Auth.cs

我正在创建一个带有身份的Web应用程序3.我使用mvc 5 c#的默认模板。当我登录时,AccountController中的这一行返回null:

var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);

AccountController.cs

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
    if (!ModelState.IsValid)
    {
        return View(model);
    }

    // This doesn't count login failures towards account lockout
    // To enable password failures to trigger account lockout, change to shouldLockout: true
    var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
    switch (result)
    {
        case SignInStatus.Success:
            return RedirectToLocal(returnUrl);
        case SignInStatus.LockedOut:
            return View("Lockout");
        case SignInStatus.RequiresVerification:
            return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
        case SignInStatus.Failure:
        default:
            ModelState.AddModelError("", "Invalid login attempt.");
            return View(model);
    }
}

我得到的错误代码:

  

异常详细信息:System.NullReferenceException:未将对象引用设置为对象实例。

感谢您的帮助

0 个答案:

没有答案