配置文件configSections节点使用实例 。
来源:互联网 发布:尤克里里调音软件 安卓 编辑:程序博客网 时间:2024/05/17 06:22
configSections为自定义节点,增加应用程序可移植性,用于配置文件上传路径,再深入应用可定义工厂方法需要加载创建的类。
1.配置configSections节点
- <configSections>
- <section name ="MyName" type="LearningConfiguration.NameSectionHandler"/>
- </configSections>
- <MyName>
- <Add key="lu" name="lulu"></Add>
- <Add key="lu2" name="66"></Add>
- </MyName>
2.定义NameSectionHandler类实现IConfigurationSectionHandler接口
- namespace LearningConfiguration
- {
- public class NameSectionHandler : IConfigurationSectionHandler
- {
- #region 隐式实现接口
- public object Create(object parent, object configContext, System.Xml.XmlNode section)
- {
- Dictionary<string, string> names = new Dictionary<string, string>();
- string key = string.Empty;
- string name = string.Empty;
- //获取配置文件中自定义节点值
- foreach (XmlNode childNode in section.ChildNodes)
- {
- if (childNode.Attributes["key"] != null)
- {
- key = childNode.Attributes["key"].Value;
- if (childNode.Attributes["name"] != null)
- {
- name = childNode.Attributes["name"].Value;
- }
- else
- {
- name = string.Empty;
- }
- names.Add(key, name);
- }
- }
- return names;
- }
- #endregion
- }
- }
3.调用
- protected void Page_Load(object sender, EventArgs e)
- {
- Dictionary<string, string> names = ConfigurationManager.GetSection("MyName") as Dictionary<string, string>;
- if (names != null)
- {
- //输出:lulu66
- foreach (string key in names.Keys)
- {
- Response.Write(names[key]);
- }
- }
- }
0 0
- 配置文件configSections节点使用实例 。
- 配置文件configSections节点使用实例
- Web.config自定义节点configSections
- C#自定义ConfigSections节点操作
- webconfig 中的 configSections 自定义节点
- configSections
- configSections
- configSections
- Web.config自定义节点configSections (转)
- 获取配置文件中configSections的配置信息!
- 获取配置文件中configSections的配置信息
- 项目配置文件app.config/configuration/configSections
- .NET配置文件中configSections的用法
- java property 配置文件
- Caffe实例开发学习笔记。——网络配置文件 Layer参数详解——
- Web.config自定义节点configSections (我还没有弄懂怎么回事.)
- 在Java Spring+Windows中使用Memcached实例
- 获取配置文件中configSections的配置信息http://www.linuxmine.com/38234.html
- textarea回车符 \r\n 在各个浏览器中表现
- Git常用命令总结2
- c#第五章指导学习:库存管理
- *[Lintcode]Two Sum 两数之和
- CI框架源码解析二十之文件上传类文件Upload.php
- 配置文件configSections节点使用实例 。
- 玩乐购与京东天猫深度合作 打造云购全网最低价
- css3 关于scaleborder
- python zip函数
- Java 分支结构 - if...else/switch
- FAQ13620]L版本AAL功能(2)——L版本AAL新架构
- Android状态栏微技巧,带你真正理解沉浸式模式
- java正则表达式之前瞻、后瞻以及正则注意点
- Application学习笔记