zoukankan      html  css  js  c++  java
  • 在web.config 的config

    在web.config中增加一个设置

    1. 在<configSections></configSections>之间构造一个Section,如
       <configSections>
          <section name="mySection" type="System.Configuration.NameValueSectionHandler,System"/>
       </configSections>

       也可以设置成一个Section组,并且组是可以嵌套的。

       <configSections>
     <sectionGroup name="myGroup">
      <sectionGroup name="nestedGroup">
        <section name="mySection" type="System.Configuration.NameValueSectionHandler,System"/>
      </sectionGroup>
      </sectionGroup>
       </configSections>


    2. 在<configuration></configuration>之间增加Sections设置,与<configSections></configSections>平级
       <mySection>
     <add key="key_one" value="1"/>
     <add key="key_two" value="2"/>
       </mySection>

       或者用Section组方式

       <myGroup>
          <nestedGroup>
             <mySection>
                <add key="key_one" value="1"/>
                <add key="key_two" value="2"/>
             </mySection>
          </nestedGroup>
       </myGroup>

    3. 读取值

    Dim config As NameValueCollection = ConfigurationSettings.GetConfig("mySection")
    或者
    Dim config As NameValueCollection = ConfigurationSettings.GetConfig("myGroup/nestedGroup/mySection")

    用上面的方法,是在要增加的配置类型比较复杂时使用,比如上面的type就是一个类。以上的每个key都是类中的一个属性。
    如果要增加的配置只是文本字符串,还可以直接用<appSetting>配置段
    <appSettings>
      <add key="aaa" value="bbb"/>
    </appSetting>

    使用时,直接用
    dim x as string = ConfigurationSettings.appSettings("aaa")
    即可

    <location></location>配置段的用法
    <location></location>用于将一套配置应用到特定的应用程序目录
    比如,
    <system.web>
        <compilation defaultLanguage="vb"/>
    </system.web>

    <location path="C#code">
      <system.web>
         <compilation defaultLanguage="cs"/>
      </system.web>
    </location>
    中,只有在C#code目录中,默认语言是C#,其它目录中都是VB

  • 相关阅读:
    创建包含前后255天所有天数的视图。
    VC获取主机名和主机信息
    在PowerDesigner增加unique约束
    差集的几种计算方法
    动态列的处理(统计)。
    一个查询语句各个部分的执行顺序
    IDC机房跳线
    软件下载链接
    IDC装机检查思路
    运维工程师之IDC系列
  • 原文地址:https://www.cnblogs.com/xiaotaoliang/p/123746.html
Copyright © 2011-2022 走看看