Use a program to modify the configuration file.
Previously, due to the need for various configuration modifications for online verification, it was too troublesome for O & M colleagues. Today, I used a program to modify the configuration file. I noted it once and for all:
[HttpPost] public ActionResult SaveSetting (string key, string value) {if (! String. IsNullOrWhiteSpace (key )&&! String. isNullOrWhiteSpace (value) & amp; ConfigurationManager. appSettings. allKeys. contains (key) {// ConfigurationManager. appSettings. set (key, value); // var config = ConfigurationManager. openExeConfiguration (ConfigurationUserLevel. none); // The method for modifying applications such as winform var config = WebConfigurationManager. openWebConfiguration ("~ "); // Modify config. AppSettings. Settings [key]. Value = value; config. Save ();} return RedirectToAction (" Index ");}
The above is the modification method in Web applications. If it is winform or wpf,
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
.
Use"
ConfigurationManager.AppSettings.Set(key, value);
The modification will only be changed in the cache, and will not be applied to the configuration file. After the application is restarted, the modification will become invalid.