Configsource properties in the Web. config configuration file

Source: Internet
Author: User
Tags connectionstrings

Each Web site will have a Web. config file. Modifying the Web. config file will cause IIS to restart, or a random carriage return will cause a reboot. Microsoft recommends that you do not save configuration content that needs to be modified in Web. config. Instead, it is placed in a single config. But how do you modify and read a config file that is stored separately? For example, you can specify that appsetting in Web. config be placed separately in a config.config file. is specified by the ConfigSource property.

Original Web. config

<?XML version= "1.0" encoding= "Utf-8"?> <Configuration>   <appSettings>    <AddKey= "Cachetimeinfo"value= "+" />     <AddKey= "Cachetimenews"value= "Ten" />     <AddKey= "Cachetimeproduct"value= "$" />     <AddKey= "Cachetimetrade"value= "5" />     <AddKey= "SiteName"value= "China fork Net"/>     <AddKey= "SiteDomain"value= "Chinaxx.com"/>   </appSettings>  <connectionStrings/>   <system.web>     <compilationDebug= "false">     </compilation>     <AuthenticationMode= "Windows" />   </system.web> </Configuration>

The file after splitting

<?XML version= "1.0" encoding= "Utf-8"?> <Configuration>    <appSettings  configSource= "Config.config" /> <connectionStrings/>   <system.web>     <compilationDebug= "false">     </compilation>     <AuthenticationMode= "Windows" />   </system.web> </Configuration>

The config file that was split Config.config

<?XML version= "1.0" encoding= "Utf-8"?><appSettings><AddKey= "Cachetimeinfo"value= "+" /><AddKey= "Cachetimenews"value= "Ten" /><AddKey= "Cachetimeproduct"value= "$" /><AddKey= "Cachetimetrade"value= "5" /><AddKey= "SiteName"value= "China fork Net"/><AddKey= "SiteDomain"value= "Chinaxx.com"/></appSettings>

After splitting, modifying the config.config does not cause IIS to restart.

Description: My config.config file and Webconfig are in the same level directory, can also be placed under different directories, but need to specify the path in the configsource attribute, in addition, My name is Config.config, you can change at will, such as the name of app.

Pay attention to the wording of config.config.

Once you add configsource to the appsettings node in Web. config, you can no longer add a node. In other words, you can't put a part of <add> in the Webconfig, and then Config.config in a part <add>

When modified, the Access node must be present otherwise: object references are not set to an instance of the object.

Configsource properties in the Web. config configuration file

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.