5
Answers

Autenthication failes Pages.User.IsInRole

Mats A

Mats A

10y
1k
1

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)