How do I modify the web.config of a web site during the setup's execution? I would like to have the user construct a connection string and then store that in the web config.
I have found this to work. But this at run time not set up.
public void ChangeAppSettings(string applicationSettingsName, string newValue)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
KeyValueConfigurationElement element = config.AppSettings.Settings[applicationSettingsName];
if (element == null)
{
config.AppSettings.Settings.Add(applicationSettingsName, newValue);
}
else
{
element.Value = newValue;
}
config.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection("appSettings");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With