Microsoft KB Archive/815178

= How To Edit the Configuration of an ASP.NET Application =

Article ID: 815178

Article Last Modified on 5/13/2007

-

APPLIES TO


 * Microsoft ASP.NET 1.0
 * Microsoft ASP.NET 1.1

-



IN THIS TASK

 * SUMMARY
 * Add Configuration Settings to the Web.config File
 * REFERENCES



SUMMARY
This step-by-step article describes how to create and how to edit the Web.config file. The Web.config file defines the behavior of ASP.NET applications. The .NET Framework, including ASP.NET, uses XML-formatted .config text files to configure applications. This is a departure from conventional registry and metabase configuration mechanisms. Currently there is no Microsoft Management Console (MMC) snap-in or other Microsoft-provided administration tool for creating and for modifying .config files.

back to the top

Add Configuration Settings to the Web.config File
Most ASP.NET applications come with a prebuilt Web.config file that can be edited with any text editor such as Notepad. Generally, Web.config files contain comments that make editing the file self-explanatory. However, you may have to add configuration items to a Web.config file that does not already have the configuration item defined. To add a standard configuration item to a Web.config file, follow these steps:  Open the Machine.config file in a text editor such as Notepad.

The Machine.config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ directory.  In the Machine.config file, locate the configuration setting you want to override in your Web.config file. When the element is more than one line, the element starts with an  line, and ends with. The element may also be self-closing and may look similar to. Note that white space is ignored. Therefore, the element may span multiple lines. The element may be preceded by a comment. The comment is contained inside markings. The   configuration element example that follows is an example of a self-closing element. The   configuration element example has multiple attributes, spans multiple lines, and has a comment at the beginning.   Copy the whole configuration element and any beginning comment to the Clipboard. Determine how the element is nested in the Machine.config file.

The Machine.config file is hierarchical, and configuration elements are nested in other elements. When you copy a configuration element from the Machine.config file to the Web.config file, you must nest that configuration element in the same element that it was copied from. To determine the element of the Machine.config file that the configuration element is contained in, scroll up in the Machine.config file until you find an element that is opened, not closed. The containing element is simple to identify because higher-level elements have less indentation.

Most ASP.NET configuration items are contained in the  element. The end of the element () must be placed after your configuration element.

Note the element that your configuration element is contained in. You must paste that element in the same element in the Web.config file. A configuration element may be nested in multiple elements. You must create all higher-level elements in the Web.config file. Close the Machine.config file and then use your text editor to open the Web.config file in the root directory of your ASP.NET application. Paste the configuration element between the beginning and the end of the element that you identified in step 4.

For example, if the configuration item is contained in the  element, the configuration item must be pasted immediately after the opening line of the  element and before the </system.web> closing line.</li> Modify the configuration element in the Web.config file to override the Machine.config setting for that application.

This setting applies to the folder that contains the Web.config file and all subfolders.</li></ol>

back to the top

<div class="references_section">