如何在安装执行期间修改网站的 web.config? 我想让用户构造一个连接字符串,然后将其存储在网络配置中。
最佳答案
我发现这个很管用。但这在运行时没有设置。
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");
}
关于visual-studio - 在 Web 安装项目期间/之后修改 Web.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1375359/