0
votes

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?

1
What happens if you create your persistent cookie? ie: setting your boolean to true in the method call. FormsAuthentication.SetAuthCookie(model.UserName, true); - ragerory
If the error code your getting on RemovePermission method is 401, so yes, then you can be sure it's a permission problem - Lucas Roselli
I tried with the true, same issue. This one is baffling me. From what i have read about the FormsAuthentication.SetAuthCookie . It only decorates the next http request with the authenticated information and nothing past that. I cant believe thats the case but that appears to be whats happening. - Dys1

1 Answers

0
votes

If you have the below, try removing it from the modules in your web.config:

<remove name="FormsAuthenticationModule" />