Managing and Configuring Web Application Projects: The Web.config File


A powerful run-time environment like ASP.NET provides many prefabricated services. As you can imagine, an individual application has many, many options for its configuration. The configuration mechanism of an environment is as important as the underlying software that it controls. Cool features that you can’t configure, or can’t figure out how to configure, are about as useful as unsecured Enron bonds.

A powerful run-time environment like ASP.NET requires excellent configuration management.

Previous run-time environments have used a central store for their configuration information. For example, classic COM used the system registry and COM+ added the COM+ catalog. ASP.NET takes a different, decentralized approach. Each application stores its ASP.NET configuration management information in a file named web.config, which is stored in the application’s own directory. Each file contains configuration information expressed in a particular XML vocabulary. Excerpts from our sample program’s web.config file are shown in Listing 3-5. This excerpt shows the compilation and custom error handling settings of this particular application. I will discuss other settings later in this chapter.

ASP.NET keeps its configuration information in individual files, each having the name web.config.

Listing 3-5: Excerpts from the sample application’s web.config file.

start example
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.web> <!-- DYNAMIC DEBUG COMPILATION Set compilation debug="true" to insert debugging symbols (.pdb information) into the compiled page. Because this creates a larger file that executes more slowly, you should set this value to true only when debugging and to false at all other times. For more information, refer to the documentation about debugging ASP.NET files. --> <compilation defaultLanguage="vb" debug="true" /> <!-- CUSTOM ERROR MESSAGES Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable. Add <error> tags for each of the errors you want to handle. --> <customErrors mode="RemoteOnly" /> </system.web> </configuration> 
end example

Web.config files can also reside in various subdirectories of an application. Each web.config file governs the operation of pages within its directory and all lower subdirectories unless overridden. Entries made in a lower-level web.config file override those made in levels above them. Some users find this counterintuitive; some don’t. The master file specifying the defaults for the entire ASP.NET system has the name machine.config and lives in the directory [system, e.g. WINNT]\Microsoft.NET\Framework\[version]\Config. Entries made in web.config files in the root directories of an individual Web application override entries made in the master file. Entries made in web.config files in subdirectories of an application override those made in the root. This relationship is shown in Figure 3-9.

A setting made in a web.config file overrides the settings made in directories above it.

click to expand
Figure 3-9: The hierarchical nature of web.config files.

Not all sections of the web.config file are configurable on all levels of subdirectory. The <sessionstate> section, for example, may not appear below an application’s root directory. You’ll have to examine the details of individual sections to find out the granularity of each.

Microsoft still has not provided a decent tool for maintaining the web.config file, even in version 1.1. You can edit the raw file using any XML editor, but it still falls far below the ease of using the .NET Framework configuration utility described in Chapter 2, or any other administrative tool in the Windows 2000 environment.

Third-party tools exist to make administration easier.

start sidebar
Tips from the Trenches

While I find this lapse inexplicable, third-party products solve the problem quite well. My favorite is the Web.Config Editor from Hunter-Stone (http://www.hunterstone.com), shown in Figure 3-10. You’ll recover the $44 they charge for it in the first hour of head- banging it helps you avoid.

click to expand
Figure 3-10: The Web.Config Editor from Hunter-Stone.

end sidebar




Introducing Microsoft. NET
Introducing Microsoft .NET (Pro-Developer)
ISBN: 0735619182
EAN: 2147483647
Year: 2003
Pages: 110

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net