Yet another answer to avoid clutter
I tried to modify your code and ran it. the following code is working fine at my end, check if you can get this to work at your end too or not.
if (Login1.UserName == "user" && Login1.Password == "user")
{
string role = "admin,member";
FormsAuthentication.SetAuthCookie(Login1.UserName, t.IsPersistent);
Session["Roles"] = role;
strRedirect = "Default.aspx";
Response.Redirect(strRedirect);
}
}
}
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
dont use this event use this event/code instead.
protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
{
if (FormsAuthentication.CookiesSupported == true)
{
if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
{
try
{
string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
string roles = Session["Roles"] as string;
e.User = new System.Security.Principal.GenericPrincipal(
new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(','));
}
catch (Exception)
{
}
}
}
}