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)

Source: Internet
Author: User
Tags connectionstrings

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)

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.