使用以下代码在web.config中出现问题:
@RequestBody
该代码有效,但是它不会更新实际的“ web.config”(webConfigFile的值),而是创建“ web.config.config”,并且仅包含connectionStrings部分:
@RequestBody
有人可以照亮
答案 0 :(得分:0)
找出解决方案,
关于OpenExeConfiguration与OpenMappedExeConfiguration的用法
OpenMappedExeConfiguration vs. OpenExeConfiguration
所以来自:
配置config = ConfigurationManager.OpenExeConfiguration(webConfigFile);
ConfigurationSection constring_section = config.GetSection(section);
if (constring_section != null && !constring_section.SectionInformation.IsProtected)
{
constring_section.SectionInformation.ProtectSection(provider);
config.Save();
}
}
到
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap() { ExeConfigFilename = webConfigFile} , ConfigurationUserLevel.None);
ConfigurationSection constring_section = config.GetSection(section);
if (constring_section != null && !constring_section.SectionInformation.IsProtected)
{
constring_section.SectionInformation.ProtectSection(provider);
config.Save();
}