模仿AppSettings进行web.config的自定义节读取[简单实用型]
来源:互联网 发布:java中的动态代理模式 编辑:程序博客网 时间:2024/06/07 06:26
作者:垃圾猪
许多人把读自义节做的很繁,看得都累死了,刚好自己的应用程序也要用自定义节,就模仿着System.Configuration.ConfigurationSettings.AppSettings做了一个读取web.config自定义配置节的类
1.实现IConfigurationSectionHandler接口的public Object Create(Object parent, object configContext, XmlNode section)方法
2.增加NameValueCollection的集合属性
第三步进行测试:
增加节点:
许多人把读自义节做的很繁,看得都累死了,刚好自己的应用程序也要用自定义节,就模仿着System.Configuration.ConfigurationSettings.AppSettings做了一个读取web.config自定义配置节的类
1.实现IConfigurationSectionHandler接口的public Object Create(Object parent, object configContext, XmlNode section)方法
2.增加NameValueCollection的集合属性
using System;
using System.Xml;
using System.Configuration;
using System.Collections.Specialized;
namespace eWebapp
{
/**//// <summary>
/// 实现对web.config自定义配置节的读取
/// 垃圾猪 2005-11-09
/// </summary>
public class AppConfig: IConfigurationSectionHandler
{
public Object Create(Object parent, object configContext, XmlNode section)
{
NameValueCollection settings;
NameValueSectionHandler baseHandler = new NameValueSectionHandler();
settings = (NameValueCollection)baseHandler.Create(parent, configContext, section);
return settings;
}
public static NameValueCollection Settings
{
get
{
NameValueCollection
collection1 = (NameValueCollection) ConfigurationSettings.GetConfig("AppConfig");
return collection1;
}
}
}
}
第二步在web.config中设置自定义节using System.Xml;
using System.Configuration;
using System.Collections.Specialized;
namespace eWebapp
{
/**//// <summary>
/// 实现对web.config自定义配置节的读取
/// 垃圾猪 2005-11-09
/// </summary>
public class AppConfig: IConfigurationSectionHandler
{
public Object Create(Object parent, object configContext, XmlNode section)
{
NameValueCollection settings;
NameValueSectionHandler baseHandler = new NameValueSectionHandler();
settings = (NameValueCollection)baseHandler.Create(parent, configContext, section);
return settings;
}
public static NameValueCollection Settings
{
get
{
NameValueCollection
collection1 = (NameValueCollection) ConfigurationSettings.GetConfig("AppConfig");
return collection1;
}
}
}
}
<configSections>
<section name="AppConfig" type="eWebapp.AppConfig, eWebapp" />
</configSections>
<section name="AppConfig" type="eWebapp.AppConfig, eWebapp" />
</configSections>
第三步进行测试:
增加节点:
<AppConfig>
<add key="testString" value="自定义节读取成功了?" />
</AppConfig>
第四步读取:<add key="testString" value="自定义节读取成功了?" />
</AppConfig>
eWebapp.AppConfig.Settings["testString"]
这么简单,源码也懒得打包了,看不懂的话就还要继续努力啊
- 模仿AppSettings进行web.config的自定义节读取[简单实用型]
- asp.net读取Web.config的<appSettings></appSettings>
- Web.config中appSettings的两种读取方法
- 读取web.config中appSettings的key值
- 使用外联文件对Web.config的appSettings进行配置
- 操作Web.config的AppSettings
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- .NET工程读取web.config或app.config中的appsettings时的注意事项
- 一个修改web.config中appSettings配置节的函数
- 一个修改web.config中appSettings配置节的函数
- 一个修改web.config中appSettings配置节的函数
- 一个修改web.config中appSettings配置节的函数
- Web.config之appsettings的另类使用
- 获取web.config中appSettings的值
- 修改web.config文件appsettings配置节
- AppSettings In web.config
- AppSettings In web.config
- Linux 网络安全和优化 (第一部分)--- Jephe Wu 翻译整理
- 网络配置文件(1)
- C/C++:如何理解复杂的声明
- 双机(多机)自动互备份方案---jinjidong
- 自定义web.config配置节(分析)
- 模仿AppSettings进行web.config的自定义节读取[简单实用型]
- CodeGear C++ Builder 2007回到传统浮动方式的设置
- javascript[对象.属性]集锦
- 青岛佳客商务酒店CRM系统项目需求分析
- Ajax.net中使用PopupControlExtender
- 在Web.config配置文件中自定义配置节点
- 当视频变成反转片――视频滤镜问题导致视频色彩失真一例
- javascript实例教程(1)
- javascript实例教程(2) 创建弹出式窗口