首页 > 代码库 > web.config configSections示例

web.config configSections示例

<configuration>

<configSections>     <section name="Tab" type="Test.Server.TabHandler,Test.Server"/>   </configSections>


<Tab>     
<add key="tab1" value="http://www.mamicode.com/标题1"/>     
<add key="tab2"  value="http://www.mamicode.com/标题2"/>

</Tab>

</configuration>

 

 

public class TabHandler : IConfigurationSectionHandler    {        public object Create(object parent, object configContext, System.Xml.XmlNode section)        {            var profileList = new List<TabModel>();             foreach (XmlNode xn in section.ChildNodes)            {                if (xn.Attributes == null)                    continue;                 profileList.Add(new TabModel

                {                     
Key = xn.Attributes["key"] == null ? string.Empty : xn.Attributes["key"].Value,                     
Value = xn.Attributes["value"] == null ? string.Empty : xn.Attributes["value"].Value                 
});             
}             
return profileList;         
}    
 }
private static List<TabModel> list = ConfigurationManager.GetSection("Tab") as List<TabModel>;
 

web.config configSections示例