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. URAL 1517 Freedom of Choice

    Freedom of Choice Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on Ural. Orig ...

  2. 极路由4pro(HC5962)安装python

    基本配置 其实极路由4.极路由4 pro.极路由B70都是一个型号的(HC5962) CPU:MT7621AT + MT7612EN + 7603EN 内存:256MB DDR3 RAM 闪存:128 ...

  3. 3、Android中Activity的跳转

    1.创建project         file->new->android application 依次填入应用名称.project名.包名 在project文件夹下找到src/com. ...

  4. JAVA性能优化的五种方式

    一,JAVA性能优化之设计优化 设计优化处于性能优化手段的上层.它往往须要在软件开发之前进行.在软件开发之前,系统架构师应该就评估系统可能存在的各种潜在问题和技术难点,并给出合理的设计方案,因为软件设 ...

  5. [JZOJ 5885] [NOIP2018模拟9.27] 物理实验 解题报告 (思维)

    题目链接: https://jzoj.net/senior/#main/show/5885 题目: 题解: 把$a$数组按升序排序 我们可以枚举$x$,发现对于任意$x$,最优情况下$y$一定等于$x ...

  6. C# 导出excel的压缩包到浏览器页面

    需求背景:TCX_1710项目产品质量导出功能,客户希望每个总成导出到一个Excel表中 实现分析:客户选择时间段,点击导出按钮,默认导出开始时间当天的数据,每个总成一个Excel,将各个Excel打 ...

  7. 编程语言与Python学习(一)

    1.1 编程与编程语言 1.1.1 编程语言 计算机的发明,是为了用机器解放人力,而编程的目的则是将人类的思想流程按照某种能够被计算机识别的表达方式传递给计算机,从而达到让计算机能够像人脑一样自动执行 ...

  8. python下py2exe打包笔记

    1.下载与python版本一致的py2exe插件包 2.安装py2exe,安装后在python目录下存在:\Lib\site-packages\py2exe\... 3.新建一个python脚本文件, ...

  9. NetworkX-画图

    参考:https://blog.csdn.net/qq951127336/article/details/54586869 1.创建图 networkx有四种图 Graph .DiGraph.Mult ...

  10. 带参数,头信息,代理,cookie爬取

    1.get传参 (1)汉字报错 :解释器器ascii没有汉字 url汉字转码 urllib.parse.quote safe="string.printtable" (2)字典传参 ...