web.Config文件的相关配置以及用法

configSections的使用方法:

configSections节点必须定义在开始位置【相当于<Configuration></Configuration>的第一个元素】

可以定义section节点,也可以配置sectionGroup节点

<configSections>
    <sectionGroup name="WebSiteConfig">
      <section name="dbProviders" type="ZC.DBUtility.WebSiteInfoHandler,ZC.DBUtility"/>
      <section name="fileUploadPath" type="ZC.DBUtility.WebSiteInfoHandler,ZC.DBUtility"/>
    </sectionGroup>
  </configSections>

<configSections>
    <section name="CustomConfig" type="OrderMvc.CustomConfig, OrderMvc"/>
</configSections>

上述两种都是可以的

获取上述两种配置节点的值通过ConfigurationManager.GetSection()方法

获取sectionGroup节点

RouteSection section =ConfigurationManager.GetSection(“WebSiteConfig/dbProviders”) as RouteSection;

RouteSection section =ConfigurationManager.GetSection(“CustomConfig”) as RouteSection;

猜你喜欢

转载自www.cnblogs.com/zyc19910109/p/9402249.html
今日推荐