在线修改KeyValue配置节

web.config中有一些自定义keyvalue配置节,想要在线修改,找了半天没找到现成的,自己写了一个:

就是类似这样的配置节:
    <system.framework>        
        
<add key="SystemFramework.Tracing.Enabled" value="True" />
        
<add key="SystemFramework.Tracing.TraceLevel" value="4" />
    
</system.framework>

写了4个类:
配置项:NameValueConfigurationItem
NameValueConfigurationItem

配置项集合:NameValueConfigurationCollection
CodeNameValueConfigurationCollection

配置节处理类:NameValueConfigurationSection
NameValueConfigurationSection

具体配置节处理类:FrameworkConfiguration
FrameworkConfiguration

配置节处理配置:
<configSections>
    
<section name="system.framework" type="Framework.Configuration.FrameworkConfiguration, Framework" />
</configSections>

修改配置:
System.Configuration.Configuration config
                = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");

            Mars.Utility.Web.Configuration.NameValueConfigurationSection
                section =
                (Mars.Utility.Web.Configuration.NameValueConfigurationSection)
            config.GetSection("system.framework");

            section.Settings.Remove(_key);
            section.Settings.Add(new Mars.Utility.Web.Configuration.NameValueConfigurationItem(_key,TextBoxValue.Text));

            config.Save(ConfigurationSaveMode.Modified);


posted @ 2008-06-30 12:26  karoc  阅读(647)  评论(0编辑  收藏  举报