https://msdn.microsoft.com/en-us/library/system.configuration.configurationsection(v=vs.110).aspx

Remarks

You use the ConfigurationSection class to implement a custom section type.

Extend the ConfigurationSection class to provide custom handling and programmatic access to custom configuration sections.

For information about how use custom configuration sections, see How to: Create Custom Configuration Sections Using ConfigurationSection.

A section registers its handling type with an entry in the configSections element.

For an example, see the configuration file excerpt摘录 shown in the Example section.

Note:

In previous versions of the .NET Framework, configuration section handlers were used to make changes to configuration settings programmatically.

Now, all the default configuration sections are represented by classes that extend the ConfigurationSection class.

Notes to Implementers:

You can use a programmatic or a declarative (attributed) coding model to create custom configuration sections:

  • Programmatic model. This model requires that for each section attribute you create a property to get or set its value and add it to the internal property bag of the underlying ConfigurationElement base class.

  • Declarative model. This simpler model, also called the attributed model, allows you to define a section attribute by using a property and decorating it with attributes. These attributes instruct the ASP.NET configuration system about the property types and their default values. With this information, obtained through reflection, the ASP.NET configuration system creates the section property objects and performs the required initialization.

The Configuration class allows programmatic access for editing configuration files.

You can access these files for reading or writing as follows:

Reading. You use GetSection or GetSectionGroup to read configuration information. Note that the user or process that reads must have the following permissions:

  • Read permission on the configuration file at the current configuration hierarchy level.

  • Read permissions on all the parent configuration files.

If your application needs read-only access to its own configuration, it is recommended you use the GetSection overloaded methods in the case of Web applications, or the ConfigurationManager.GetSection method in the case of client applications.

These methods provide access to the cached configuration values for the current application, which has better performance than the Configuration class.

Note:

If you use a static GetSection method that takes a path parameter, the path parameter must refer to the application in which the code is running;

otherwise, the parameter is ignored and configuration information for the currently-running application is returned.

Writing. You use one of the Save methods to write configuration information. Note that the user or process that writes must have the following permissions:

  • Write permission on the configuration file and directory at the current configuration hierarchy level.

  • Read permissions on all the configuration files.

The following example shows how to implement a custom section programmatically.

For a complete example that shows how to implement and use a custom section implemented using the attributed model, seeConfigurationElement.

删除section

如上图所示,需要删除名为fiftyOne的sectiongroup。并且添加一个section为ajaxControlToolKit的section。

 [TestFixture]
class KenticoUpgrade7To11Test
{
[Test]
public void Test()
{
var filePath = @"/";
var configuration = WebConfigurationManager.OpenWebConfiguration(filePath,"Test"); var sectionGroups = configuration.SectionGroups;
var sections = configuration.Sections; var sectionGroupToDelete = "fiftyOne";
sectionGroups.Remove(sectionGroupToDelete); var sectionToAdd = "ajaxControlToolkit";
ConfigurationSection section = sections.Get(sectionToAdd);
var ajaxControlToolkitConfigSection = section as AjaxControlToolkitConfigSection;
if (ajaxControlToolkitConfigSection == null)
{
//add
ajaxControlToolkitConfigSection = new AjaxControlToolkitConfigSection();
sections.Add(sectionToAdd, ajaxControlToolkitConfigSection);
}
else
{
//update
}
ajaxControlToolkitConfigSection.SectionInformation.Type = "AjaxControlToolkit.AjaxControlToolkitConfigSection, AjaxControlToolkit";
ajaxControlToolkitConfigSection.SectionInformation.RequirePermission = false; configuration.Save();
}
}

ConfigurationSection的更多相关文章

  1. ASP.NET使用ConfigurationSection在Web.Config创建自定义配置节集合

    核心代码 using System; using System.Data; using System.Configuration; using System.Web; using System.Web ...

  2. ASP.NET使用ConfigurationSection在Web.Config创建自定义配置节

    主要代码,一定要继续System.Configuration.ConfigurationSection,具体的节点名称可以自行修改 using System; using System.Data; u ...

  3. c# ConfigurationSection

    怎么把自己的配置文件配置到app.config中? 方案1:在app.config中添加 <!--应用配置--> <appSettings configSource="Co ...

  4. 自定义ConfigurationSection,创建多个嵌套的ConfigurationElementCollection节点

    由于接口地址都是固定的,所以想到使用自定义节点,来将接口都配置到web.config中. 很快,v1.0版本出炉: public class RequestConfigSection : Config ...

  5. .Net 配置文件--继承ConfigurationSection实现自定义处理类处理自定义配置节点

    除了使用继承IConfigurationSectionHandler的方法定义处理自定义节点的类,还可以通过继承ConfigurationSection类实现同样效果. 首先说下.Net配置文件中一个 ...

  6. .Net 配置文件——继承ConfigurationSection实现自定义处理类处理自定义配置节点

    除了使用继承IConfigurationSectionHandler的方法定义处理自定义节点的类,还可以通过继承ConfigurationSection类实现同样效果. 首先说下.Net配置文件中一个 ...

  7. [转]通过继承ConfigurationSection,在web.config中增加自定义配置

    本文转自:http://www.blue1000.com/bkhtml/2008-02/55810.htm 前几天写了一篇使用IConfigurationSectionHandler在web.conf ...

  8. .Net 配置文件——继承ConfigurationSection实现自己定义处理类处理自己定义配置节点

    除了使用继承IConfigurationSectionHandler的方法定义处理自己定义节点的类.还能够通过继承ConfigurationSection类实现相同效果. 首先说下.Net配置文件里一 ...

  9. [2014-02-19]ConfigurationSection:让web.config配置更有条理

    本文针对新手 使用Web.config的配置信息,一般都习惯于使用 ConfigurationManager.AppSettings["ConfigKey"] 当程序不断迭代,开发 ...

  10. 使用 ConfigurationSection 创建自定义配置节

    我们可以通过用自己的 XML 配置元素来扩展标准的 ASP.NET 配置设置集,要完成这一功能,我们必须实现继承System.Configuration.ConfigurationSection 类来 ...

随机推荐

  1. 从ORA-27300,ORA-27301到ORA-00064

        近期因为session数量添加,须要调整session,也就是要调整process參数. 看是比較简单的一个问题,却遭遇了ORA-27300,ORA-27301.因为这个涉及到了有关内核參数k ...

  2. 朝花夕拾——finally/final/finalize拨云雾见青天

    Java编程中.常常会使用到异常处理,而finally看似的是try/catch后对逻辑处理的完好,事实上里面却存在非常多隐晦的陷阱.final常见于变量修饰,那么你在内部类中也见过吧.finaliz ...

  3. (转)C/C++ 宏详解

    众多C++书籍都忠告我们C语言宏是万恶之首,但事情总不如我们想象的那么坏,就如同goto一样.宏有一个很大的作用,就是自动为我们产生代码.如果说模板可以为我们产生各种型别的代码(型别替换),那么宏其实 ...

  4. legend---十一、thinkphp事务中if($ans1&&$ans2){}else{}方式和try{}catch{}方式事务操作的区别在哪里

    legend---十一.thinkphp事务中if($ans1&&$ans2){}else{}方式和try{}catch{}方式事务操作的区别在哪里 一.总结 一句话总结:执行的条件其 ...

  5. m_Orchestrate learning system---十七、页面美观的关键是什么

    m_Orchestrate learning system---十七.页面美观的关键是什么 一.总结 一句话总结:图片用好看的 1.项目板块化? 就是一个个模块,能复用的话很快的 页面由这一个个模块拼 ...

  6. javascript系列-class8.BOM

    1.浏览器对象模型( browser object model )   什么是BOM?    提起BOM就不得不提起JavaScript的构成.ECMAScript为JavaScript的核心,但是要 ...

  7. 92.bower 需要git

    转自:https://blog.csdn.net/chenleismr/article/details/50458496Bower 是基于 Git 之上的包管理工具,它提供的包其源头都是一个 Git ...

  8. CentOS7系统安装完MySQL后启动MySQL提示无服务

    重新安装MariaDB数据库即可解决,MySQL所有命令可通用 MariaDB MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,开发这个分支的原因之一是:甲骨文公司收购了My ...

  9. 关于Tomcat的启动

    1.Tomcat分为安装版和解压版. 2.在Tomcat的解压版的bin路径下启动startup.bat的时候,如果没有启动成功,请检查是否设置了JAVA_HOME 3.建议不要在环境变量里面设置CA ...

  10. 005.JMS可靠性机制

    1. 消息接收确认 JMS消息只有在被确认之后,才认为已经被成功地消费了.消息的成功消费通常包含三个阶段: 客户接收消息 客户处理消息 消息被确认 在事务性会话中,当一个事务被提交的时候,确认自动发生 ...