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

  • 相关阅读:
    巧用SQL Server Profiler
    Linq结果直接返回实体对象
    C#(MVC) Word 替换,填充表格,导出并下载PDF文档
    C#匿名类型(Anonymous Type)学习日记
    C#Lambda表达式学习日记
    C#事件(Event)学习日记
    C#委托(Delegate)学习日记
    C#隐私信息(银行账户,身份证号码,名字)中间部分特殊字符替换(*)
    CSS布局模型
    Visual Studio 内置快速生产代码简写集合
  • 原文地址:https://www.cnblogs.com/xiaotaoliang/p/123746.html
Copyright © 2011-2022 走看看