Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,


I am using asp.net membership provider for assiging Roles and Managing Roles.
In my application I have 3 sub folders like ADMIN,USERS and MANAGERS with some some default pages to each role.
I created the roles and I assigned roles to the registered users.

I login to the application with USERS role then I am accessing the USERS web pages only but now if the user types the URL of unauthenticated folders/pages like ADMIN or MANAGERS,he can also logging in but I dont want this to be happened,If he tries to other role pages I want to redirect that user to Login page.

Can anyone help me how to achieve this whether using the asp.net code or web.config file.

Thanks in advance...
Posted

1 solution

First, make sure your web.config in the root of the application has the forms authentication setup taking note to set the login page:

XML
<authentication mode="Forms">
     <forms name="auth" loginUrl="~/Default.aspx" timeout="20" cookieless="UseCookies" path="/" requireSSL="false" slidingExpiration="true" protection="All"/>
   </authentication>


Once you have done this each sub folder must have a web.config. i.e. /Admin/web.config.

In this you will need to state the access rights for the users. i.e.

XML
<configuration>
  <system.web>
    <authorization>
      <allow roles="ADMIN" />
      <allow roles="MANAGERS" />
      <deny roles="USERS" />
      <deny roles="?" />
    </authorization>
  </system.web>
</configuration>


If an unauthenticated user or incorrect role hits the folder they will be re-directed to the login page!
 
Share this answer
 
Comments
jaipal0908 31-May-12 2:32am    
Thank you,its working fine

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