开发者

How do I change configsource value in remote configuration file

开发者 https://www.devze.com 2023-03-03 22:00 出处:网络
I\'m using ConfigurationManager.OpenMappedExeConfiguration to read and modify web.config files of remote web services. This works well for the most part.

I'm using ConfigurationManager.OpenMappedExeConfiguration to read and modify web.config files of remote web services. This works well for the most part. The config file splits out开发者_开发技巧 the unity configuration section using

    <unity configSource="Unity1.config"/>

How can I change this to point at Unity2.config? I tried

    Config.Sections["unity"].SectionInformation.ConfigSource = "Unity2.config"

This does update the web.config file. However, it also causes Unity2.config to be overwritten with the contents of Unity1.config, which is not what I want.

Also, is there a way to refresh a Configuration object opened in this way?


var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
var section = config.GetSection(UnityConfigurationSection.SectionName) as UnityConfigurationSection;
if (section == null)
{
     section = new UnityConfigurationSection();
     config.Sections.Add(UnityConfigurationSection.SectionName, section);
}

section.SectionInformation.ConfigSource = "unity.config";
config.Save(ConfigurationSaveMode.Full);

Works fine

0

精彩评论

暂无评论...
验证码 换一张
取 消