ASP.NET Configuration




Configuration information for an ASP.NET Web application is stored in a file named Web.config. The
configuration file contains a nested hierarchy of XML tags and subtags with attributes that specify the con-
figuration settings. This configuration file is deployed when the ASP.NET application is deployed on a
Web server. Configuring a Web site requires configuration of settings according to the server’s capabilities
and requirements. Configuring a Web site might also require developers to write code. At a later stage, the
site administrator might need to change the settings of the site or the server on which the site has been
deployed so as to enhance the performance of the site. If the change in settings involves embedding
values into code, however, it becomes very complicated and difficult for both the developer and the
administrator to reconfigure the application.

As you can see, the application deployment process requires a rich and flexible configuration system.
The configuration system should enable developers to easily associate settings with an installable
application without having to embed values into code. The system should also enable administrators to
easily adjust or customize these values after the deployment of the application on the application Web
server. The ASP.NET configuration system based on Web.config file fulfills both these requirements. To
accomplish this, ASP.NET provides a rich set of configuration settings that you can specify in the

Web.config file.

ASP.NET Configuration Architecture

ASP.NET uses a hierarchical configuration architecture that uses an XML format. In the hierarchical
configuration architecture, whenever a client makes a request for an ASP.NET application or a specific
ASP.NET resource, ASP.NET checks the settings for the URL requested by the client in a hierarchical
fashion. The check is carried out using the configuration files located in the path for the requested URL.
These settings are then logged or cached by the application Web server to speed up any future requests
for ASP.NET resources.

All configuration information resides between the <configuration> and </configuration> root
XML tags. Configuration information between the tags is grouped into two main areas: the configuration
section handler declaration area and the configuration section settings area.

Web.config versus Machine.config

Consider a scenario wherein the Web site has only one Web.config file in the root directory. Although
the Web site has only one Web.config file in the directory structure, the Web site actually uses two
configuration files because a file named machine.config exists in the %windir%\Microsoft
.NET\Framework\v2.0.<buildnumber>\CONFIG directory. In this path, <buildnumber> represents
the build number of the Microsoft .NET Framework. In future releases, this build number will change,
and therefore the actual name of the folder might also change. This machine.config file is at the
highest level and is called the machine-level configuration file. This machine-level configuration file
comes with the .NET Framework and contains the default settings for all the applications built using
.NET Framework.

All ASP.NET directories and subdirectories inherit settings from this machine-level configuration file;
however, a Web.config file can also be located at the Web site level, and if it is not overridden at a
lower level, it will apply to all ASP.NET resources on the Web site.