IConfigurationSectionHandler 接口的用法
2007-07-13 16:32
281 查看
对asp.net 的配置文件即熟悉又陌生,熟悉的是天天在使用,陌生是实现原理还是个糊涂的概念.
今天终于花了点时间了解一下IConfigurationSectionHandler 接口的用法 ,引以入门.
首先建立一 RobsunConfigSectionHandler 专案,代码如下 :
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
namespace RobsunConfigSectionHandler
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public class RobsunParaSectionHandler:IConfigurationSectionHandler
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
IConfigurationSectionHandler 成員#region IConfigurationSectionHandler 成員
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public object Create(object parent, object configContext, XmlNode section)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RobsunPara para = new RobsunPara();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
foreach (XmlNode xn in section.ChildNodes)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
switch (xn.Name)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
case "path":
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
para.Path = xn.SelectSingleNode("@value").InnerText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
break;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
case "companyName":
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
para.CompanyName = xn.SelectSingleNode("@value").InnerText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
break;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
case "isPrivate":
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
para.IsPrivate = bool.Parse(xn.SelectSingleNode("@attribute").InnerText);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
break;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return para;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
RobsunParaSectionHandler类实现 IConfigurationSectionHandler 接口.
RobsunPara类(实际就是参数类)的代码如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public class RobsunPara
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
codecode#region code
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private string _path = "";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private string _companyName = "";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private bool _isPrivate = false;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public string Path
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
get ...{ return _path; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
set ...{ _path = value; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public string CompanyName
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
get ...{ return _companyName; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
set ...{ _companyName = value; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public bool IsPrivate
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
get ...{ return _isPrivate; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
set ...{ _isPrivate = value; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
ConfigurationHander类的创建工作已完成,次handler的工作必须配合如下配置文件的格式(其实的配置文件依赖handler).这里是web.config(三种配置文件任一,web.config,App.config,machine.config ,前两种会覆盖machine.config,当然这里是没法子在App.config配置了 ~Q~ )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<configuration>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<configSections>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<sectionGroup name="robsunGroup">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<section name="robsunSection" type="RobsunConfigSectionHandler.RobsunParaSectionHandler,RobsunConfigSectionHandler"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</sectionGroup>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</configSections>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<robsunGroup>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<robsunSection>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<path value="NONE"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<companyName value="Robsun"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<isPrivate attribute="true"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</robsunSection>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</robsunGroup>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<appSettings/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<connectionStrings/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<system.web>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
...
准备代码都已完成.剩下的就是拿来用了....
这里为了简单起见,就直接在page_load里实现了:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public partial class _Default : System.Web.UI.Page
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected void Page_Load(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RobsunConfigSectionHandler.RobsunPara para
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
= ConfigurationManager.GetSection("robsunGroup/robsunSection") as RobsunConfigSectionHandler.RobsunPara;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Response.Write("CompanyName: " + para.CompanyName + "<br>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Response.Write("Path: " + para.Path + Environment.NewLine + "<br>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Response.Write("isPrivate: " + para.IsPrivate.ToString() + "<br>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
以上只是对IConfigurationSectionHandler 接口的简单事例.配置文件的强大也只有在以后的工作中慢慢体会了.
今天终于花了点时间了解一下IConfigurationSectionHandler 接口的用法 ,引以入门.
首先建立一 RobsunConfigSectionHandler 专案,代码如下 :
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
namespace RobsunConfigSectionHandler
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public class RobsunParaSectionHandler:IConfigurationSectionHandler
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
IConfigurationSectionHandler 成員#region IConfigurationSectionHandler 成員
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public object Create(object parent, object configContext, XmlNode section)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RobsunPara para = new RobsunPara();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
foreach (XmlNode xn in section.ChildNodes)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
switch (xn.Name)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
case "path":
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
para.Path = xn.SelectSingleNode("@value").InnerText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
break;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
case "companyName":
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
para.CompanyName = xn.SelectSingleNode("@value").InnerText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
break;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
case "isPrivate":
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
para.IsPrivate = bool.Parse(xn.SelectSingleNode("@attribute").InnerText);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
break;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return para;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
RobsunParaSectionHandler类实现 IConfigurationSectionHandler 接口.
RobsunPara类(实际就是参数类)的代码如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public class RobsunPara
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
codecode#region code
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private string _path = "";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private string _companyName = "";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private bool _isPrivate = false;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public string Path
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
get ...{ return _path; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
set ...{ _path = value; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public string CompanyName
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
get ...{ return _companyName; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
set ...{ _companyName = value; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public bool IsPrivate
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
get ...{ return _isPrivate; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
set ...{ _isPrivate = value; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
ConfigurationHander类的创建工作已完成,次handler的工作必须配合如下配置文件的格式(其实的配置文件依赖handler).这里是web.config(三种配置文件任一,web.config,App.config,machine.config ,前两种会覆盖machine.config,当然这里是没法子在App.config配置了 ~Q~ )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<configuration>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<configSections>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<sectionGroup name="robsunGroup">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<section name="robsunSection" type="RobsunConfigSectionHandler.RobsunParaSectionHandler,RobsunConfigSectionHandler"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</sectionGroup>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</configSections>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<robsunGroup>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<robsunSection>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<path value="NONE"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<companyName value="Robsun"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<isPrivate attribute="true"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</robsunSection>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</robsunGroup>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<appSettings/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<connectionStrings/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<system.web>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
...
准备代码都已完成.剩下的就是拿来用了....
这里为了简单起见,就直接在page_load里实现了:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public partial class _Default : System.Web.UI.Page
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected void Page_Load(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RobsunConfigSectionHandler.RobsunPara para
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
= ConfigurationManager.GetSection("robsunGroup/robsunSection") as RobsunConfigSectionHandler.RobsunPara;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Response.Write("CompanyName: " + para.CompanyName + "<br>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Response.Write("Path: " + para.Path + Environment.NewLine + "<br>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Response.Write("isPrivate: " + para.IsPrivate.ToString() + "<br>");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
以上只是对IConfigurationSectionHandler 接口的简单事例.配置文件的强大也只有在以后的工作中慢慢体会了.
相关文章推荐
- NopCommerce学习笔记(一)----IConfigurationSectionHandler 接口的用法
- 实现IConfigurationSectionHandler接口来编写自定义配置
- .Net——实现IConfigurationSectionHandler接口定义处理程序处理自定义节点
- .net IConfigurationSectionHandler接口应用
- .Net——实现IConfigurationSectionHandler接口定义处理程序处理自己定义节点
- [原创]自定义Config例子,使用IConfigurationSectionHandler 接口
- .net IConfigurationSectionHandler接口应用
- IConfigurationSectionHandler 接口的实现
- .Net——实现IConfigurationSectionHandler接口定义处理程序处理自定义节点
- IConfigurationSectionHandler 接口
- .Net——实现IConfigurationSectionHandler接口定义处理程序处理自定义节点
- (转).net webconfig使用IConfigurationSectionHandler自定section
- [C#]DLL继承IConfigurationSectionHandler即可访问宿主的.exe.config
- ASP.NET 实践:使用 IConfigurationSectionHandler 创建自定义配置段
- IConfigurationSectionHandler 使用~
- IConfigurationSectionHandler的线程安全性问题
- Implements IConfigurationSectionHandler interface,create a custom configuration section handler
- [C#]DLL继承IConfigurationSectionHandler即可访问宿主的.exe.config
- [C#]DLL继承IConfigurationSectionHandler即可访问宿主的.exe.config
- 使用IConfigurationSectionHandler在web.config中增加自定义配置