Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I am trying to implement Role based Form Authentication in my Website and been stuck with it. Problem is its not redirecting the user depending on the user role.

Below is the code to authenticate the user. I want to allow only user with Admin role to access pages inside Admin folder. Even after providing correct id and password the Admin is not able redirected to Login.aspx.
C#
if (isValidUser)
        {
            string role = "Admin";
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, TextBox1.Text, DateTime.Now, DateTime.Now.AddMinutes(1), false, role, FormsAuthentication.FormsCookiePath);
            string encTicket = FormsAuthentication.Encrypt(ticket);
            Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
            Response.Redirect("~/Admin/admin_index.aspx");
        }
        else
            Response.Redirect("Login.aspx");

Extracts from my Web.Config
XML
<authentication mode="Forms">
  <forms loginUrl="Login.aspx" timeout="1" cookieless="UseDeviceProfile"/>
</authentication>
<authorization>
  <deny users="?"/>
</authorization>

<location path="Admin">
    <system.web>
        <authorization>
            <allow roles="Admin"/>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>

Any help really appreciated.
Posted
Updated 13-May-13 18:45pm
v3

1 solution

 
Share this answer
 
Comments
ROHITH.SUNNY 16-May-13 7:14am    
Appreciate your response, but I was expecting someone to point out as to what I am doing wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900