I have a strange issue happening while creating this MVC project. Yesterday I was able to log in as a user, it was authenticated and everything worked fine. Today for some reason the user is getting a successful login and when I try to redirect the user to my Index view in my Parts controller I get returned directly to the log in page.
Login
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = @"~\Views\Parts\Index";
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
var user = _userRepo.GetUserDetailsByEmail(model.Email);
if(user == null)
{
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
if (!ModelState.IsValid || !user.Active)
{
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); //Get to here
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);
}
}
I checked User.Identity.IsAuthenticated and it returned false even after the sign in is successful. What am I doing wrong here? I have forms authentication enabled as well.
My Parts controller is decorated with the [Authorize] attribute. Which I believe is why the user is being redirected to log in (since the user is never authenticated).
EDIT
I noticed that the .ASPXAUTH cookie is not going through anymore. Could this be due to a bug or is there some steps I can take to fix that?