Web.config change during / after the Web Setup project

How do I change the web.config of a website during installation? I would like the user to build a connection string and then save it in a web configuration.

+3
source share
3 answers
0

I found this to work. But this is not configured at runtime.

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");
}
0
source

Source: https://habr.com/ru/post/1716831/


All Articles