使用自定义的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文件中不可用

posted @ 2015-03-19 14:25  王加陈  阅读(266)  评论(0编辑  收藏  举报