But this variable will not be a fixed value, will change according to the actual situation, such as in the need to read a configuration file path, and this path is the site published the actual hard drive path, if directly is the compile-time state, no problem. However, if site IIS replaces the path, you need to modify the parameters in this web.config. It would be more reasonable and convenient if you could modify this compile-time state to a run-time state. This requires a scenario in which Web.config can be dynamically modified in code.
Code
Copy Code code as follows:
<summary>
Write to Web.config
</summary>
<param name= "Item" >appsettings etc </param>
<param name= "key" > Key </param>
<param name= "Value" > Value </param>
public void Writeconfig (string item, string key, String value)
{
if (item = = "")
{
item = "AppSettings";
}
Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration ( System.Web.HttpContext.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 ();
}
}