I write the following code to access the page but this is not working for me
if (User.Identity.IsAuthenticated)
{
if (Context.User.IsInRole("DistrictAdmin"))
{
if (!IsPostBack)
{
}
}
else
{
Response.Redirect("Default.aspx");
}
}
else
{
Response.Redirect("Default.aspx");
}
My Login check code
string RoleTypeID;
objLogin.UserName = txtUsername.Text;
objLogin.Password = txtPassword.Text;
if (objLogin.getRoles(out RoleTypeID))
{
Session["RoleID"] = RoleTypeID;
FormsAuthenticationTicket oAuthTicket = new FormsAuthenticationTicket(1, txtUsername.Text, DateTime.Now, DateTime.Now.AddMinutes(20), false, RoleTypeID.ToString(), FormsAuthentication.FormsCookiePath);
string encryptoAuthTicket = FormsAuthentication.Encrypt(oAuthTicket);
HttpCookie oCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptoAuthTicket); // Name of auth cookie
if (oAuthTicket.IsPersistent) oCookie.Expires = oAuthTicket.Expiration;
HttpContext.Current.Response.Cookies.Add(oCookie);
if (RoleTypeID == "DistrictAdmin" || RoleTypeID == "CampusAdministrator" || RoleTypeID == "LPACMember")
{
Response.Redirect("LEPstudentrecords.aspx");
}
}
else
{
lblInvalid.Visible = true;
}
and in my web.config i set as follows
<roleManager enabled="false" />
<authentication mode="Forms">
<forms loginUrl="Default.aspx"
timeout="20" />
</authentication>
<sessionState mode="InProc" timeout="180"></sessionState>
But i am unable to get the role even if he is authenticated can any one tell what to do
Here is the image after authenticated every thing is getting right but i am unable to access that page

You are adding the role string as ‘UserData’ to the
FormsAuthenticationTicket. There is no magic that will infer this value to a role.I suggest you consult the documentation again.
http://msdn2.microsoft.com/en-us/library/system.web.security.formsauthenticationticket.formsauthenticationticket
See http://www.codeproject.com/KB/web-security/formsroleauth.aspx for an example without RoleManager.