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 systemrootMicrosoft. NETFrameworkversionNumberCONFIGMachine. 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.