Introducing ASP.NET - Configuring the ASP.NET Web Site
(Page 5 of 5 )
Almost all aspects of .NET, and by extension ASP.NET, can be customized via XML configuration files. These are readable (but not writeable) from .NET applications, so you can extend their applicability by defining custom configuration sections and parameters.
For an ASP.NET web site, configuration is achieved by placing a file with the correct syntax, named web.config, at the web site directory. You can add more web.config files in child directories that you want to configure more specifically. For example, if you wanted to deny access to only a certain part of your web site, your web.config file might contain
<configuration>
<system.web>
<authorization>
<allow roles="Admins"/>
<deny users="*"/>
</authorization>
</system.web>
</configuration>
This example allows access to all members of the Admins role and denies access to all other users unless modified by other web.config files.
There are many other sections in a configuration file, and it is more efficient to refer you to the Microsoft documentation at http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/cpgenref/html/gngrfaspnetconfigura-
tionsectionschema.asp than try to cover them all here. We will discuss only the most important section from the point of view of web developers, <browserCaps>.
The <browserCaps> section controls the settings of the browser capabilities class, System.Web.HttpBrowserCapabilities. It is contained directly within the <system.web> section.
<configuration>
<system.web>
<browserCaps>
For example, the following sample web.config demonstrates parsing the USER_AGENT HTTP header for the platform type. It uses a regular expression to match portions of text of the user agent string with known systems. If you have used ASP before, you will recognize that the file specifies name/value pairs in the form of assignment statements, similar to the IIS browscap.ini files. For example, the line platform=WinNT sets the value of the platform field to the string WinNT.
<configuration>
<system.web>
<browserCaps>
<result type="System.Web.HttpBrowserCapabilities, System.Web"/>
<use var="HTTP_USER_AGENT"/>
browser=Unknown
version=0.0
majorver=0
minorver=0
frames=false
tables=false
<filter>
<case match="Windows 98|Win98">
platform=Win98
</case>
<case match="Windows NT|WinNT">
platform=WinNT
</case>
</filter>
</browserCaps>
</system.web>
</configuration>
Within the ASP.NET page’s code, we could also examine the value of the variables platform, browser, version, and so on, and make decisions regarding the content we display.
If Request.Browser.Platform="Win95" Then
Response.Write("Your platform cannot host .NET applications<BR>")
End If
By this point you might be getting impatient to see more ASP.NET code. The next chapter is full of it!
Summary We covered a lot of theory and concepts in this chapter. It is time to look at some practical examples of applying ASP.NET technology using Dreamweaver to solve everyday web programming problems. In the meantime, if you would like to see who can start hosting your ASP.NET web sites, take a look at http://www.asp.net/Default.aspx?tabindex=8&tabid=40, where you will also find links to various ASP.NET community sites.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from chapter three of the book ASP.NET Web Development with Macromedia Dreamweaver MX, written by Costas Hadjisotiriou et al. (Apress, 2004; ISBN: 1590593480). Check it out at your favorite bookstore. Buy this book now.
|
|