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 类来 ...
随机推荐
- jquery mobile常用的data-role类型介绍
转自原文 jquery mobile常用的data-role类型介绍 data-role参数表: page 页面容器,其内部的mobile元素将会继承这个容器上所设置的属性 header ...
- HTML---经常使用标签总结与实践
什么是HTML? 超文本标记语言,标准通用标记语言下的一个应用. "超文本"就是指页面内能够包括图片.链接,甚至音乐.程序等非文字元素. 超文本标记语言的结构包含" ...
- Google翻译PDF文档
Google翻译PDF文档 翻译软件虽多如牛毛,但有关整段/全文翻译,堪用的软件极少, 涉及专业技术的文献.胜任翻译工作的人力稀缺.少不了project师讴心沥血. 由于多是PDF格式.即使要翻译个概 ...
- iOS开发—在@interface,@implementation和@property中变量的定义
一直搞不懂在OC中变量在@interface和@implementation中有什么区别,定义@property又有什么不同,查了很多资料,总结如下: //ViewController.h @inte ...
- php和js区别
php和js区别 两者在语法上类似,楼上说的对,js=javascript是工作在浏览器端的脚本语言,他所提交的数据是交给浏览器来处理的.但是现在的Ajax技术已经可以把js提交的数据交付到浏览器来处 ...
- nyoj--891--找点(贪心)
找点 时间限制:2000 ms | 内存限制:65535 KB 难度:2 描述 上数学课时,老师给了LYH一些闭区间,让他取尽量少的点,使得每个闭区间内至少有一个点.但是这几天LYH太忙了,你们帮 ...
- B树索引与索引优化
B树索引与索引优化 MySQL的MyISAM.InnoDB引擎默认均使用B+树索引(查询时都显示为“BTREE”),本文讨论两个问题: 为什么MySQL等主流数据库选择B+树的索引结构? 如何基于索引 ...
- 日常问题记录-- java.lang.IllegalArgumentException: taglib definition not consistent with specification version
转自:https://www.cnblogs.com/carterzhang/p/4288650.html 背景: tomcat8.0中使用taglib 错误表现: java.lang.Illegal ...
- POJ 1945 暴搜+打表 (Or 暴搜+判重)
思路: 呃呃 暴搜+打表 暴搜的程序::稳稳的TLE+MLE (但是我们可以用来打表) 然后我们就可以打表过了 hiahiahia 可以证明最小的那个数不会超过200(怎么证明的我也不知道),然后就直 ...
- X86 X64 X86_64 AMD64 区别
X86:32位(一般i386是32位CPU的统称) X64:64位(代表CPU:IA64,现在几乎没有这样纯粹的64位CPU,都是兼容32位的64位CPU,如下) X86_64:兼容32位的64位CP ...