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