Original: Use Configsource in the Web. config file to avoid dynamically modifying Web. config to cause ASP. NET Restart (Add a config file to manage user data)
As we all know, after modifying the configuration file Web. config in ASP. NET, it causes the application to restart and all sessions (session) are lost. However, the application configuration information in the configuration file is the best choice, in the background to modify the configuration to cause all session loss is very uncomfortable, this time can be changed in the configuration files often need to change the configuration section outside, such as appsetting section.
First, the original Web. config file:
<?xml version= "1.0" encoding= "Utf-8"?>
<configuration>
<appSettings>
<add key= "Cachetimeinfo" value= "/>"
<add key= "Cachetimenews" value= "ten"/>
<add key= "cachetimeproduct" value= "/>"
<add key= "Cachetimetrade" value= "5"/>
<add key= "SiteName" value= "China Fork Net"/>
<add key= "SiteDomain" value= "chinaxx.com"/>
</appSettings>
<connectionStrings/>
<system.web>
<compilation debug= "false" >
</compilation>
<authentication mode= "Windows"/>
</system.web>
</configuration>
Two (1/2), now Web. config files
<?xml version= "1.0" encoding= "Utf-8"?>
<configuration>
ConfigSource= "Config/appsettings.config"/>
<connectionStrings/>
<system.web>
<compilation debug= "false" >
</compilation>
<authentication mode= "Windows"/>
</system.web>
</configuration>
Appsettings.config file in the Config directory of two (2/2) and now
<?xml version= "1.0" encoding= "Utf-8"?>
<appSettings>
<add key= "Cachetimeinfo" value= "/>"
<add key= "Cachetimenews" value= "ten"/>
<add key= "cachetimeproduct" value= "/>"
<add key= "Cachetimetrade" value= "5"/>
<add key= "SiteName" value= "China Fork Net"/>
<add key= "SiteDomain" value= "chinaxx.com"/>
</appSettings>
This will not cause a reboot if the Config/appsettings.config file is modified in the program.
Use configsource in the Web. config file to avoid dynamically modifying Web. config to cause ASP. NET Restart (Add a config file to manage user data)