Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ASP.NET WebConfig : Location and Authroization Tags

0.00/5 (No votes)
5 Feb 2009 2  
Here’s is an article saying, how to use the Authorization Tag in Web.Config  As per the MSDN Articles, the Location>Authorization Mechanism works

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Here’s is an article saying, how to use the Authorization Tag in Web.Config

 

As per the MSDN Articles, the Location>Authorization Mechanism works on a TOP to DOWN Approach. As if we consider the case, where we need to Define Separate Roles for Folders in the Root Directory.

 

Application Root >> Members (Premium Paid)     --- this folder is for the users, who are registered with site and have paid some amount for some services, and contains the relevant files or pages.

Application Root >> Admin --- this folder is for the Site Admin

Application Root >> Members (Non-paid Members) --- this folder is for the users, who have not paid for any special or paid service but still they are registered with the site for services like Newsletter or Blogging etc.

 

For this case we need to do the following :

 

1.       Implement the Same Forms Authentication for ASP.NET Login Control

2.       Add Location tag for Members(Premium Paid) as :

 

<location path=”Members(Premium Paid)”>

<authorization>

<allow roles=”Premium_Paid_Members” />  ---- Allow the desired role first

                <deny users=”*” /> --- now Deny all roles and users, this follows the TOP to DOWN approach

                <deny roles=”*” /> --- now Deny all roles and users, this follows the TOP to DOWN approach

</authorization>

</location>

 

3.       Add Location tag for Admin as :

<location path=”Admin”>

                <authorization>

                                <allow roles=”Admin” />       ---- You may add verbs as per the requirement like for Only Post Data (verbs=”post”)

                                <deny users=”*” />

                <deny roles=”*” /> --- now Deny all roles and users, this follows the TOP to DOWN approach

                </authorization>

</location>

 

4.       Add Location tag for Admin as :

<location path=” Members (Non-paid Members)”>

                <authorization>

                                <allow roles=”Members” />

                                <deny users=”*” />

                <deny roles=”*” /> --- now Deny all roles and users, this follows the TOP to DOWN approach

                </authorization>

</location>

 

Conclusion : we must allow the desired Roles or the Users before denying all users and roles on the folder, so that proper access for all the folders can be maintained at same time.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here