Multiple Security Settings In ASP.Net
page 1 of 1
Published: 15 Dec 2004
Unedited - Community Contributed
Abstract
In a previous article I provided some samples to allow password protection of a folder in ASP.Net based on some settings in the root config.web file. Since that article I have had a few people ask if it was possible to secure multiple locations - each potentially with their own security requirements.
by Web Team at ORCS Web
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 8875/ 23

In a previous article I provided some samples to allow password protection of a folder in ASP.Net based on some settings in the root config.web file. Since that article I have had a few people ask if it was possible to secure multiple locations - each potentially with their own security requirements.

Well, the answer is yes, it is possible and it isn't even very hard. Below is a sample config.web file, that when placed in the web root will secure two different folders. One is /admin/ and the other is /protected/.

Access to the /admin/ folder is controlled in lines 13 through 19. One line 16 it is specified that the only people that can access this folder are people that have authenticated via ASP.Net. It does not matter who the person is, as long as they have provided a valid username and password (noted on lines 06 through 07).

Access to the /protected/ folder is more secure. The setting on line 24 specify that the user "User1" is allowed access to this folder. This line alone is not good enough to trigger the security. It also needs to be specified to deny all users (other than "User1"), which is done by the code on line 25.

As you have probably noted by now, the authorization section will accept either a "deny" or an "allow" statement, so you can specifically control the type of access (or lack of access). You might have also noted that you can use various items for the "users" property. Using "*" means to deny (or allow) everyone; using "?" means to deny (or allow) any known users (users who have not yet authenticated); you can also specify an individual username for this property if you want to limit access to only certain users.

01: <configuration> 
02:   <system.web> 
03:     <authentication mode="Forms"> 
04:       <forms name="TestAuthCookie" loginUrl="login.aspx" timeout="30"> 
05:         <credentials passwordFormat="Clear"> 
06:           <user name="user1" password="pass1"/> 
07:           <user name="user2" password="pass2"/> 
08:         </credentials> 
09:       </forms> 
10:     </authentication> 
11:   </system.web> 
12: 
13:   <location path="admin"> 
14:     <system.web> 
15:       <authorization> 
16:         <deny users="?" /> 
17:       </authorization> 
18:     </system.web> 
19:   </location> 
20: 
21:   <location path="protected"> 
22:     <system.web> 
23:       <authorization> 
24:         <allow users="user1" /> 
25:         <deny users="*" /> 
26:       </authorization> 
27:     </system.web> 
28:   </location> 
29: </configuration> 

As you can see, the config.web file allows for some fairly complex security restrictions once you understand the required format. Wrapping all of these security configurations into the config.web file - as opposed to implementing them with IIS settings - allows a few benefits. The most obvious are: The developer can configure the security themselves without getting a server administrator involved; and deploying the application to multiple servers is easier since all of the settings are actually in the code and no system changes are needed.

By Brad Kingsley, founder and president of ORCS Web, Inc. - a company that provides managed hosting services for clients who develop and deploy their applications on Microsoft Windows platforms.



User Comments

Title: THANKS   
Name: steven
Date: 2008-01-04 9:33:59 PM
Comment:
great
Title: thank you !   
Name: bk_arthur_311@yahoo.com
Date: 2007-02-07 12:47:18 PM
Comment:
thank you verry much !
Title: Thanks   
Name: rw
Date: 2005-06-01 5:48:27 AM
Comment:
Thanks - after trawling for 2 hrs I finally understand it.

Thanks again!
Title: Dr.   
Name: Ron Liu
Date: 2005-03-17 11:52:18 AM
Comment:
rliu@tranquilsys.com

This save me a whole day. Great article. Do you have any sugestion with regarding using session variable or cookies for navigation tracking

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2017 ASPAlliance.com  |  Page Processed at 2017-12-16 6:03:33 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search