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;

 

posted @ 2018-08-01 16:53  冬月二四  阅读(169)  评论(0编辑  收藏  举报