How to Create a web.config file for an ASP.NET Application

This step-by-step article describes how to create a web.config file for an ASP.NET application. The .NET Framework, and ASP.NET in particular, uses XML-formatted .config files to configure applications.

The .NET Framework relies on .config files to define configuration options. The .config files are text-based XML files. Multiple .config files can, and typically do, exist on a single system.

System-wide configuration settings for the .NET Framework are defined in the machine.config file. The machine.config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ folder. The default settings that are contained in the machine.config file can be modified to affect the behavior of .NET applications on the whole system.

You can change the ASP.NET configuration settings for a single application if you create a web.config file in the root folder of the application. When you do this, the settings in the web.config file override the settings in the machine.config file.

You can create a web.config file by using a text editor such as Notepad. You must create a text file that is named web.config in the root directory of your ASP.NET application. The web.config file must be a well-formed XML document

The following example shows a minimal web.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
  </system.web>
</configuration>

The ASP.NET configuration system provides the following benefits:

  • Configuration information is stored in XML-based text files. You can use any standard text editor or XML parser to create and edit ASP.NET configuration files.
  • Multiple configuration files, all named web.config, can appear in multiple directories on an ASP.NET Web application server. Each web.config file applies configuration settings to its own directory and all child directories below it. Configuration files in child directories can supply configuration information in addition to those inherited from parent directories. Also, the child directory configuration settings can override or modify settings defined in parent directories. The root configuration file named systemroot\Microsoft.NET\Framework\versionNumber\CONFIG\Machine.config provides ASP.NET configuration settings for the entire web server.
  • At run time, ASP.NET uses the configuration information provided by the web.config files in a hierarchical virtual directory structure to compute a collection of configuration settings for each unique URL resource. The resulting configuration settings are then cached for all subsequent requests to a resource. Note that inheritance is defined by the incoming request path (the URL), not the file system paths to the resources on disk (the physical paths).
  • ASP.NET detects changes to configuration files and automatically applies new configuration settings to web resources affected by the changes. The server does not have to be rebooted for the changes to take effect. Hierarchical configuration settings are automatically recalculated and recached whenever a configuration file in the hierarchy is changed. The <processModel> section is an exception.
  • The ASP.NET configuration system is extensible. You can define new configuration parameters and write configuration section handlers to process them.
  • ASP.NET helps protect configuration files from outside access by configuring Internet Information Services (IIS) to prevent direct browser access to configuration files. HTTP access error 403 (forbidden) is returned to any browser attempting to request a configuration file directly.

If you have made a mistake while editing web.config, you may recreate it with default configuration. To do so, go to your Website Panel. Go to Web Sites under Web. Then click on a website for which you require a default web.config file.

Once you see the screen as below, simply click on the Update button. This will restore your web.config to its default configuration.

This concludes how to create a web.config file for an ASP.NET application

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , | Posted under ASP .NET 3.5, DotNet/Windows Hosting, Programming/Coding | RSS 2.0

2 Comments on How to Create a web.config file for an ASP.NET Application

  1. Very good info. Lucky me I found your site by accident (stumbleupon).
    I’ve saved it for later!

Leave a Reply

Your email address will not be published. Required fields are marked *


7 − = 6

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>