Analysis of ASP. NET Configuration File hierarchy and inheritance

Source: Internet
Author: User

You can distribute ASP. NET configuration files in the entire application directory to configure ASP. NET applications in an inherited hierarchy. With this structure, you can implement the configuration details required by the application at the appropriate directory level without affecting the configuration settings at the higher directory level.

ASP. NET configuration file Configuration Structure

ASP. NET configuration files are called Web. config files, which can appear in multiple directories of ASP. NET applications. The ASP. NET configuration hierarchy has the following features:

Use the configuration file that is applied to the directory where the configuration file is located and all its sub-directories.

Allows you to place configuration data in a location that gives it a proper range (the entire computer, all Web applications, a single application, or subdirectories in the application.

You can override the configuration settings inherited from a higher level in the configuration hierarchy. You can also lock configuration settings to prevent them from being overwritten by lower-level configuration settings.

Organize the configured logical group into segments.

ASP. NET configuration file configuration inheritance

All. NET Framework applications inherit basic configuration settings and default values from a file named systemroot \ Microsoft. NET \ Framework \ versionNumber \ CONFIG \ Machine. config. The Machine. config file is used for server-level configuration settings. Some of these settings cannot be overwritten in a configuration file at a lower level in the hierarchy.

The. NET client application (console and Windows Application) uses the configuration file ApplicationName. config to override the inherited settings. ASP. NET applications use a configuration file named Web. config to override the inherited settings.

The root of the ASP. NET configuration hierarchy is a file called the root Web. config file, which is located in the same directory as the Machine. config file. The root Web. config file inherits all the settings in the Machine. config file. The root Web. config file includes settings applied to all ASP. NET applications running a specific version of. NET Framework. Since each ASP. NET application inherits the default configuration settings from the root Web. config file, you only need to create a Web. config file to override the default settings.

Inheritance in the ASP. NET configuration file set Element

Some configuration elements are collections, such as namespaces and mermerrors.

In a collection, add sub-elements to add configuration settings to the collection, remove the configuration settings by pressing the remove sub-element key, or clear the entire set by using the clear sub-element. Unless repeated items are allowed, the settings added in the sub-configuration file will overwrite the one-key settings in the parent configuration file.

Notes for ASP. NET configuration files

Some collections in earlier versions of. NET Framework use different element names for add sub-elements. For example, the customErrors element uses the error sub-element to add a custom error to the set.

If you receive a request for a file that does not exist in the SubDir1 directory, ASP. NET will start to search for configuration hierarchies and start from the local Web. config File (if it exists, it may be in the current directory or in the parent directory of the current directory. ASP. NET searches for the error element (ASP. NET setting architecture) of customErrors whose statusCode attribute is "404. Once ASP. NET finds the 404 error in configuration settings, the URL in the redirect attribute is returned as a response.

This section describes the hierarchy and Inheritance of ASP. NET configuration files. It is helpful for you to understand the hierarchy and Inheritance of ASP. NET configuration files.

  1. Analysis on the use of CustomValidator, an ASP. NET data verification control
  2. Analysis of embedded code block application in ASP. NET web pages
  3. Analysis on SQL Server Database Backup Recovery in ASP. NET
  4. Analysis of Theme functions in ASP. NET development skills
  5. Analysis of ASP. NET configuration file format

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.