I figured out how to do it. First, give the
Once you've added that line,
then add either in a separate class, partial, or wherever the following:
private void SaveSetting(string SettingName, string SettingValue)
{
//connect to the webconfiguration file
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
//get the setting that you want to update
KeyValueConfigurationElement setting = config.AppSettings.Settings[SettingName];
//assign the new value to the setting
setting.Value = SettingValue;
//save the configuration changes
config.Save(ConfigurationSaveMode.Minimal, false);
// Force a reload of the changed section.
ConfigurationManager.RefreshSection("appSettings");
}
This will get the key that you are looking for, update it. You can actually see when this happens, if in Visual Studio you have the file open. It will prompt you that a change has been made to the file, and ask if you wish to reload it.
Edit: Note, that even when you force the RefreshSection, from what I understand, that'll only refresh the web.config section to reload. Appearently, it won't always refresh external files. So your changes may not show up right away. ARG.
If anyone has a solution to this, I'd appreciate it.
No comments:
Post a Comment