I am having a problem with MVC4 user authorization.
System.Web.Security.Membership.ValidateUser returns true.
Then it gets to FormsAuthentication.SetAuthCookie and I see a cookie in my browser.
Then User.Identity.IsAuthenticated still evaluates to false for some reason.
User.Identity.IsAuthenticated is still false after a redirect and stays false.
[AllowAnonymous]
[HttpPost]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (System.Web.Security.Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
User.Identity.IsAuthenticatedwon’t be set to true until the next request after callingFormsAuthentication.SetAuthCookie().See http://msdn.microsoft.com/en-us/library/twk5762b.aspx