Click here to Skip to main content
15,938,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
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));

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

<location path="Admin">
            <allow roles="Admin"/>
            <deny users="*"/>

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

1 solution

Share this answer
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