Detailed explanation of Web. config (priority of configuration file search)

Source: Internet
Author: User

If you are still confused about the web. config configuration file in Asp.net, please refer toArticleIt will give you a brief understanding of the Asp.net runtime mechanism.

This is often the case during development.ProgramFor the sake of confidentialitySource codeReleased along with the project, and the development environment and deployment environment may be different (for example, the database is different ).CodeYou need to change the code and re-compile the code when you deploy the configurations. This deployment method is very troublesome.
In. NET provides a convenient way to save the project configuration information, that is, using the configuration file, the configuration file suffix is generally. config. In Asp.net, the default file name is web. config. Each web. config file is an XML-based text file and can be saved to any directory in the Web application. When a web application is published, the Web. config file is not compiled into the DLL file. If the client changes in the future, you only need to open the Web. config file in notepad and edit the relevant settings to use it again, which is very convenient. The following is the question:
Configuration File Search priority

In. NET provides a configuration file for the current machine, which is a machine. config, which is located in % WinDir % \ Microsoft. net \ framework \ v2.0.50727 \ config \ file (% Windir % is the system directory under the system partition, in command line mode, enter % WINDIR % and press enter to view the system directory of the current machine. In Windows2003 and WindowsXP, % Windir % is the Windows directory under the system partition, in Windows2000, % Windir % is the WINNT directory under the system partition. On the author's machine, the system directory is C: \ Windows ). This file defines the configurations for the winform and Asp.net applications on the current machine.

There is also a web. config file in this folder, which contains common configurations of the Asp.net website. The content of the web. config file is as follows:

When IIS is started on the Asp.net website, it loads the configuration information in the configuration file and caches the information so that you do not have to read the configuration information each time. During the running process, the Asp.net application monitors the changes in the configuration file. Once the configuration information is edited, the configuration information will be re-read and cached.
When we want to read information about a node or node group, we search for the information as follows:

(1) If the Web. config file exists in the directory where the current page is located, check whether the node name to be searched exists. If yes, return the result and stop searching.
(2) If there is no web. config file in the directory where the current page is located or the name does not exist in the web. config file, find its parent directory until the root directory of the website.
(3) If the root directory of the website does not exist. config file or web. if the node name does not exist in the config file, it is in % WinDir % \ Microsoft. net \ framework \ v2.0.50727 \ config \ Web. search in the config file.
(4) In % WinDir % \ Microsoft. net \ framework \ v2.0.50727 \ config \ Web. if the config file does not contain any node, the node is in % WinDir % \ Microsoft. net \ framework \ v2.0.50727 \ config \ machine. search in the config file.
(5) If not found, null is returned.

Therefore, if you have specific Configuration Requirements for a website or folder, you can create a web under the corresponding folder. the Config File overwrites the web in the upper-level folder. in the config file. The configuration information can be searched only once and then cached for future calls. When the Asp.net application is running. when the config file is changed, the corresponding application will be restarted, and the user session information stored in the server memory will be lost (such as the session stored in the memory ). Each time some software (such as anti-virus software) accesses web. config, the access time attribute of Web. config is modified, and the Asp.net application is restarted.

 

Last added NOTE: This is not original, reproduced in: http://www.zxbc.cn/html/20081110/67614.html

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.