Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi...

i want to know how can i define roles in web config .

i have a logintable (name,password,userrole) and userrole is of three types (admin,teacher,student).... and my website have three folder according to my role ...

now i have written something like below in web.config...

HTML
<pre lang="HTML">
XML
<location path="Admin">
    <system.web>
      <authorization>
        <allow roles="Admin" />
        <deny roles="*" />
      </authorization>
    </system.web>
  </location>
  <location path="Teacher">
    <system.web>
      <authorization>
        <allow  roles="Teacher" />
        <deny roles="*" />
      </authorization>
    </system.web>
  </location>
 <location path="Student">
    <system.web>
      <authorization>
        <allow  roles="Student" />
        <deny roles="*" />
      </authorization>
    </system.web>
  </location>




and in login page i have code like below ....

C#
if (Roles.IsUserInRole("Admin"))
       {
           Response.Redirect("~/Admin/Default.aspx");
       }
       if (Roles.IsUserInRole("Teacher"))
       {
           Response.Redirect("~/Teacher/Default.aspx");
       }
if (Roles.IsUserInRole("Student"))
       {
           Response.Redirect("~/Student/Default.aspx");
       }





but my code does not execute any of above condition...Please help me and tell me how can i manage my roles in login page to web config page ..

can i create role in web config then please tell me how ...

please help me .....
Posted
Updated 21-Apr-13 21:19pm
v2

1 solution

 
Share this answer
 
Comments
Mangal Deep Gupta 22-Apr-13 3:30am    
hey thank u but i want c# code ...Means how can i match role from the database to the web.config.. If u know that then please tell me ...thank u

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