Introduction

ASP.NET provides a convenient, extensible, XML-based mechanism for configuring ASP.NET and applications that run under it. It is an improvement over the IIS metabase that was awkward to change, required IIS to be restarted, and was not easily replicated on additional servers. By contrast, ASP.NET automatically detects changes to the web.config file and transparently restarts the application; there is no need to restart IIS. Replicating an ASP.NET application configuration is as simple as copying the web.config file to the new server.

Configuration File Hierarchy

ASP.NET uses a hierarchy of configuration files. The machine.config file contains the settings for the server and is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ folder. You can create web.config files to configure each of your applications, overriding the settings in machine.config. Folders within the application can have web.config files to customize the configuration of portions of the application and override the settings in the .config files higher up the hierarchy.

Structure and Use of web.config

The basic structure of web.config has a format similar to machine.config. The idea is that you add to web.config only those entries for which you want to override settings in machine.config. At a minimum, web.config must have a <configuration> element and a child element, such as a <system.web> element. The following is a minimal web.config file:

 <?xml version="1.0"?> <configuration> ...

Get ASP.NET 2.0 Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.