在web.config中添加简单的自定义段

最简单的,key-value类型:

1 <configuration>
2     <configSections>
3         <section name="KeyValueSection" type="System.Configuration.NameValueSectionHandler"/>
4     </configSections>
5     <KeyValueSection>
6         <add key="0" value="v0"/>
7         <add key="1" value="v1"/>
8     </KeyValueSection>
9 </configuration>


在代码中获取值:

1 using System.Collections.Specialized;  //NameValueCollection 
2 
3 NameValueCollection collection = ConfigurationManager.GetSection("ServerTableNames"as NameValueCollection;
4 string serverTableName = collection[serverType.ToString()];


参考:

在web.config或app.config中增加自定义配置方法大全 

Web.config中的自定义配置节

posted on 2010-10-05 00:55  lbsx  阅读(206)  评论(0)    收藏  举报