Click here to Skip to main content
11,578,213 members (66,422 online)
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 21:17pm
Edited 21-Apr-13 21: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 Richard MacCutchan 165
1 Peter Leow 150
2 OriginalGriff 120
3 Afzaal Ahmad Zeeshan 100
4 Frankie-C 85
0 OriginalGriff 880
1 Sergey Alexandrovich Kryukov 685
2 Abhinav S 573
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 393


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2015
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