I have a login method that succsfully communicates with my DB and sets the authCookie in 4.5.1.
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model)
{
//call my DB
FormsAuthentication.SetAuthCookie(model.UserName, false);
return RedirectToAction("Index");
}
I then redirect to an index page decorated With the [Authorize] and it works as expected.
On this page i have an HttPost method that gets called from Jquery/Ajax:
[HttpPost]
public ActionResult RemovePermission(string staff)
{
if (User.Identity.IsAuthenticated)
{
DataAccessor d = new DataAccessor();
d.Remove(staff);
}
return RedirectToAction("Index", "Home");
}
if i decorate this method with [Authorize], it does not work(never steps into the method, presumably because it does not think the user is logged in.). If i dont and check if the user is authenticated in the above if statement, they are not.
//Web.Config forms loginUrl="~/Home/LogIn" timeout="1000"
What am i missing?
FormsAuthentication.SetAuthCookie(model.UserName, true);- ragerory