Mats A

Mats A

  • NA
  • 59
  • 28k

Autenthication failes Pages.User.IsInRole

Mar 30 2014 3:48 AM

My authentication stopped working all of a sudden and recent backps do not seem to do the trick. Can any of you see what is wrong, at the loginpage I verify the user and assign the user the "admin" role like this:

if (isAdmin(email, password))
{
 loadAdmin(email, password);
        strRole = "admin";
        ticket = new FormsAuthenticationTicket(1, email, DateTime.Now, DateTime.Now.AddMinutes(30), false, strRole, FormsAuthentication.FormsCookiePath);
        Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)));
        Response.Redirect("admin_pages_admin.aspx");
}

At the "admin_pages_admin.aspx" page I have this.

if (!Page.User.IsInRole("admin") && !Page.User.IsInRole("user"))
                Response.Redirect("admin_pages_default.aspx");


This evaluates to true and I'm redirected to the loginpage


Answers (5)