Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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...
 
<pre lang="HTML">
<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 ....
 
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 21-Apr-13 22:17pm
Edited 21-Apr-13 22:19pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
mangal deep gupta at 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)

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100