ConfigurationSection
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的更多相关文章
- ASP.NET使用ConfigurationSection在Web.Config创建自定义配置节集合
核心代码 using System; using System.Data; using System.Configuration; using System.Web; using System.Web ...
- ASP.NET使用ConfigurationSection在Web.Config创建自定义配置节
主要代码,一定要继续System.Configuration.ConfigurationSection,具体的节点名称可以自行修改 using System; using System.Data; u ...
- c# ConfigurationSection
怎么把自己的配置文件配置到app.config中? 方案1:在app.config中添加 <!--应用配置--> <appSettings configSource="Co ...
- 自定义ConfigurationSection,创建多个嵌套的ConfigurationElementCollection节点
由于接口地址都是固定的,所以想到使用自定义节点,来将接口都配置到web.config中. 很快,v1.0版本出炉: public class RequestConfigSection : Config ...
- .Net 配置文件--继承ConfigurationSection实现自定义处理类处理自定义配置节点
除了使用继承IConfigurationSectionHandler的方法定义处理自定义节点的类,还可以通过继承ConfigurationSection类实现同样效果. 首先说下.Net配置文件中一个 ...
- .Net 配置文件——继承ConfigurationSection实现自定义处理类处理自定义配置节点
除了使用继承IConfigurationSectionHandler的方法定义处理自定义节点的类,还可以通过继承ConfigurationSection类实现同样效果. 首先说下.Net配置文件中一个 ...
- [转]通过继承ConfigurationSection,在web.config中增加自定义配置
本文转自:http://www.blue1000.com/bkhtml/2008-02/55810.htm 前几天写了一篇使用IConfigurationSectionHandler在web.conf ...
- .Net 配置文件——继承ConfigurationSection实现自己定义处理类处理自己定义配置节点
除了使用继承IConfigurationSectionHandler的方法定义处理自己定义节点的类.还能够通过继承ConfigurationSection类实现相同效果. 首先说下.Net配置文件里一 ...
- [2014-02-19]ConfigurationSection:让web.config配置更有条理
本文针对新手 使用Web.config的配置信息,一般都习惯于使用 ConfigurationManager.AppSettings["ConfigKey"] 当程序不断迭代,开发 ...
- 使用 ConfigurationSection 创建自定义配置节
我们可以通过用自己的 XML 配置元素来扩展标准的 ASP.NET 配置设置集,要完成这一功能,我们必须实现继承System.Configuration.ConfigurationSection 类来 ...
随机推荐
- luogu 1865 数论 线性素数筛法
洛谷 1865 数论 线性素数筛法 最基本的线性素数筛法,当做复习欧拉筛法了,没有尝试过使用更暴力的筛法... WA了一次,手抖没打\n 传送门 (https://www.luogu.org/prob ...
- 洛谷 P2111 考场奇遇
P2111 考场奇遇 题目背景 本市的某神校里有一个学霸,他的名字叫小明(为了保护主人公的隐私,他的名字都用“小明”代替).在这次的期中考试中,小明同学走桃花运,在考场上认识了一位女生,她的名字叫小红 ...
- 洛谷 P1278 单词游戏
P1278 单词游戏 题目描述 Io和Ao在玩一个单词游戏. 他们轮流说出一个仅包含元音字母的单词,并且后一个单词的第一个字母必须与前一个单词的最后一个字母一致. 游戏可以从任何一个单词开始. 任何单 ...
- UI_UIImagePickerController(读取图片)
创建图片 #pragma mark - 创建 photoImageView - (void)createphotoImageView { self.photoImageView = [[UIImage ...
- [博弈] hdu 3683 Gomoku
题意: 两个人下五子棋.给你现有棋盘,推断在三步之内的胜负情况. 输出分为几种. 1.棋盘不合法 2.黑或白在第一步赢下在(x,y)点,多个输出x最小的.y最小的. 3.输在第二步 4.黑或白在第三步 ...
- oracle实现自增id
--oracle实现自增id --创建一张T_StudentInfo表 create table T_StudentInfo ( "id" integer not null pri ...
- 关于iOS7中UIView效果失效问题的解决
最近想做一个跑马灯的效果.于是写出了例如以下的跑马灯效果的代码...可是调试发现,在iOS6下动画是能够运行的,可是在iOS7下动画并不运行,没有达到预期的效果. [_scrollLabel size ...
- 创建一个web user control
1.创建文件 添加,然后选择web user control 2.添加控件 在工具栏搜索button,然后拖动三个button上去 <%@ Control Language="C#&q ...
- JAVA配置Tomcat
1.下载tomcat,我jdk是1.8的,网上查了一下,说要安装tomcat8及以上的tomcat 尝试点击,弹出, 2.配置环境 3.安装通过cmd安装 4.点击开启服务 5.输入localhost ...
- apiCloud实现加载更多效果,基本完美~
apiCloud实现加载更多效果 1.接口支持,加入参数page. $page = $this->_request('page','trim','1'); $pagesize = 10; // ...