<configuration> <configSections> <sectionGroup name="" type=""> </sectionGroup> </sectionGroup> <!--自定义配直web.config参数--> <section name="mySection" type="System.Configuration.SingleTagSectionHandler" /> <!--自定义配直web.config参数--> </configSections> <!--自定义配直web.config参数--> <mySection section1 ="one" section2="two" section3="three" section4="four" /> <!--自定义配直web.config参数--> <appSettings> <add key="" value="" /> </appSettings> <connectionStrings/> </configuration>
using System; using System.Collections; using System.Configuration; public class ReaderConfiguration { /// <summary> /// 读取web.config中自定义参数值 /// </summary> /// <returns>String</returns> public String ReadMySettings() { IDictionary mySettings = (IDictionary)ConfigurationSettings.GetConfig("mySetting"); string section1 = (string)sampleTable["section1"]; string section2 = (string)sampleTable["section2"]; string section3 = (string)sampleTable["section3"]; string section4 = (string)sampleTable["section4"]; return section1 + "," + section2 + "," + section3 + "," + section4 ; } }