asp.net自定义配置节

asp.net自定义配置节

<configSections>
 <sectionGroup name="xiaos">
  <section name="xiao1" type="com.dyh.Fi,dyh"></section> 
/**注意:这里的type=","里的dyh是com.dyh.Fi所在的Assemble而不是命名空间**/ 
 </sectionGroup>
 
  </configSections> 
 
  <xiaos>
 <xiao1>
  <add key="yaya" value="gaga"></add>
 
 </xiao1>
 
  </xiaos>

public class Fi:System.Configuration.NameValueFileSectionHandler
 {   


 }


注意如果直接用:
<section name="SourceViewer" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </configSections>
后面的版本号等等参数一定不能省略。


后台处理:
using System.Collections.Specialized;

NameValueCollection ha=(NameValueCollection)System.Configuration.ConfigurationSettings.GetConfig("xiaos/xiao1");
   Response.Write(ha["yaya"]); 

.net规定,所有能够处理配置节的类必须要实现IConfigurationSectionHandler接口,而IConfigurationSectionHandler接口很简单,只有一个object Create(object parent,object configContext,XmlNode section)方法,这个方法不需要主动调用,它是在ConfigurationSettings.GetConfig这个静态方法的时候自动调用的,也就是说,当你在程序中使用ConfigurationSettings.GetConfig来获取配置节的时候,.net会根据改配置节声明中所定义的类名和路径自动实例化配置节处理类,并调用Create方法。但是你可以覆写create方法,也可以不覆写,直接调用getConfig即可。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值