Specific ways to modify the Web. config node in ASP.

Source: Internet
Author: User
However, this variable does not have a fixed value, it will change according to the actual situation, such as the need to read a configuration file path, and this path is the actual hard disk path published by the site, if the direct is the compile-time state, no problem. However, if the site IIS is replacing the path, you will need to modify the parameters in this web. config. It would be more reasonable and convenient to modify this compile-time state to run-time state. This requires a scenario where you can dynamically modify the Web. config in your code.
Code

 <summary>//write Web. config//</summary>/<param name= "Item" >appsett Ings </param>//<param name= "key" > Key </param>//<param name= "value" > Value </para             m> public void Writeconfig (string item, string key, String value) {if (item = = "")             {item = "appSettings"; } Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration (System.Web.Http             Context.Current.Request.ApplicationPath); Appsettingssection appsection = (appsettingssection) config.             GetSection (item);                 if (appsection.settings[key] = = null) {APPSECTION.SETTINGS.ADD (key, value); Config.             Save ();                 } else {appSection.Settings.Remove (key);                 APPSECTION.SETTINGS.ADD (key, value); Config. SavE (); }         }
Related Article

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.