0

UPDATE:

Fixed this by adding

ConfigureAuth(app);

to Startup.Auth.cs


I'm creating a web application with identity 3. I'm using the default template for mvc 5 c#. When I'm logging in, this line in AccountController returns 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);
    }
}

The error code I'm getting:

Exception Details: System.NullReferenceException: Object reference not set to an object instance.

Thanks for any help

CAMELYON
  • 31
  • 1
  • 9
  • 2
    Are you sure it returning null? It's seems more likely that SignInManager or model is null. What I mean is. Which like is the nullref occuring at? – Mikael Eliasson Mar 04 '17 at 21:04
  • What I mean is that is doesn't return anything, the code just stops there. – CAMELYON Mar 04 '17 at 21:08
  • 1
    Then the problem is that it's throwing an exception, not returning null. Have you created the SignInManager? – Mikael Eliasson Mar 04 '17 at 21:15
  • Yes, inside of App_Start/Startup_Auth.cs `app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext(ApplicationUserManager.Create); app.CreatePerOwinContext(ApplicationSignInManager.Create);` – CAMELYON Mar 04 '17 at 22:51

0 Answers0