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 (); } }