IIS 6: The Complete Reference

Web Configuration File—web.config

The web.config file is a deployment configuration file for IIS. The programmer can use the web.config file as a means of setting IIS to run in a particular way during development. When the ASP.NET project gets rolled to production, the instance or virtual directory of IIS is immediately configured according to the configuration described in the web.config file. The settings in the file pertain to all subdirectories that exist subordinate to the directory in which it was placed unless another web.config file is encountered. This means that a web application can be made up of multiple web.config files. If there is no web.cong file found in a web application, the machine.config file located in the $:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG folder will be used as a default. The v1.1.4322 portion of the file path is subject to reflect the version of the .NET Framework that you are hosting on your server. Listing 14-8 shows the default web.config file that was produced in the ASP.NET project SimpleWF.

Listing 14-8: Source Code of web.config file

<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.web> <compilation  defaultLanguage="c#"  debug="true" /> <customErrors mode="RemoteOnly" /> <authentication mode="Windows" /> <trace  enabled="false"  requestLimit="10"  pageOutput="false"  traceMode="SortByTime"   localOnly="true" /> <sessionState   mode="InProc"   stateConnectionString="tcpip=127.0.0.1:42424"   sqlConnectionString=      "data source=127.0.0.1;user id=sa;password="   cookieless="false"   timeout="20" /> <globalization   requestEncoding="utf-8"   responseEncoding="utf-8" /> </system.web> </configuration>

The application settings are set as child elements to the appSettings element, which is a child element of the configuration element. A web.config file will not contain any application settings by default. Application settings are typically added by the dynamic properties for controls pasted on web forms in the Web Forms Designer or manually by the developer. Application settings contain initialization values for components in the application. Utilization of the web.config file for storing and extracting application settings will be covered in greater detail in Chapter 15.

The system.web element has child elements that contain settings that control the mechanics of the web application itself. If child elements are not present, the application will use the settings found in the machine.config file. Although not a comprehensive list of potential settings, the following six child elements of the system.web element are found in a web.config file created by Visual Studio .NET by default:

Категории