zoukankan      html  css  js  c++  java
  • 使用自定义的config

    string configPath = System.IO.Path.Combine(HttpRuntime.AppDomainAppPath.ToString(), "WebAddress.config");//配置文件的地址
                ExeConfigurationFileMap configMap = new ExeConfigurationFileMap(configPath);
                configMap.ExeConfigFilename = configPath;
                Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
                var section = (AppSettingsSection)config.GetSection("ipAddress"); //获取config section
                string results = section.Settings[key].Value;
                return results;

    附 WebAddress.config文件:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="ipAddress" type="System.Configuration.AppSettingsSection" />
      </configSections>
     
      <ipAddress>
        <add key="adminTarget" value="202.127.207.182:9999"></add>
        <add key="adminPres" value="202.127.207.184:7001"></add>
        <add key="knowledge" value="202.127.207.182:8097"></add>
        <add key="synReport" value="202.127.207.182:8888"></add>
      </ipAddress>

    </configuration>

    注:namevalue 类型 在自定义的config文件中不可用

  • 相关阅读:
    移动端Web前端注解
    Atom 必备插件
    Gulp 前端自动化构建
    RESTful API 设计
    Cookie 的 增删查
    三步实现 AngularJS URL 去 # 号
    AngularJS $http 之 POST 传参
    Angular.JS中使用$watch监听模型变化
    AngularJS $apply() 解析
    [个人笔记]IDEA+MAVEN+testNG(reportNG)
  • 原文地址:https://www.cnblogs.com/wangjiachen/p/4350333.html
Copyright © 2011-2022 走看看