zoukankan      html  css  js  c++  java
  • web.config增加组和调用

    一,在web.config中的configuration节点下我们可以添加自己的配置,如下:

      <TestSectionGroup>
        <TestSection>
          <add key="Url" value="xxxxx" />
          <add key="Token" value="xxxxx" />
          <add key="Key" value="xxxxx" />
        </TestSection>
      </TestSectionGroup>

    二,但是刚开始这样添加是使用不了的,我们需要在configuration的configSections下注册

     <configSections>
         <sectionGroup name="TestSectionGroup">
          <section name="TestSection" type="System.Configuration.NameValueSectionHandler,System, Version=4.0.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089" />
        </sectionGroup> 
      </configSections>

    三,调用代码

            private static NameValueCollection TestSection = (NameValueCollection)ConfigurationManager.GetSection("TestSectionGroup/TestSection");
            private static string Url= TestSection ["Url"];
            private static string Token= TestSection ["Token"];
            private static string Key= TestSection ["Key"];
  • 相关阅读:
    Python运算符及逻辑运算
    Python编码、流程控制、格式化输出
    Docker私有仓库Harbor部署与使用
    react
    理事会
    关于elementui form表单过长,看不到未填项
    js
    vue 父子传值
    养生
    html知识点
  • 原文地址:https://www.cnblogs.com/May-day/p/8554955.html
Copyright © 2011-2022 走看看