.net App.config 自定义配置 获取多个节点

本文介绍了一种通过App.config文件配置多个更新URL的方法,并展示了如何使用.NET框架中的ConfigurationManager来读取这些URL配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(1) App.config如下:

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
  <section name="updateurl" type="Sale.SvrPySale.SynchroConfigSerializerSectionHandler,SvrPySale" />
 </configSections>
<!-- 跟新URL地址配置-->
  <updateurl>
    <add key="svrUrl" value="A:http://localhost:8080/api/updateA"/>
    <add key="svrUrl" value="B:http://localhost:8080/api/updateB"/>
    <add key="svrUrl" value="C:http://localhost:8080/api/updateC"/>
    <add key="svrUrl" value="D:http://localhost:8080/api/updateD"/>
    <add key="svrUrl" value="E:http://localhost:8080/api/updateE"/>
    <add key="svrUrl" value="F:http://localhost:8080/api/updateF"/>
  </updateurl>
  </configuration>

 

注: type="Sale.SvrPySale.SynchroConfigSerializerSectionHandler,SvrPySale"中Sale.SvrPySale.SynchroConfigSerializerSectionHandler 是一个实现System.cinfiguration.IConfigurationSectionhandler并实现Create方法的类,SvrPySale 是,该类所在的项目名称

=================================================================================

(2)项目名称: SvrPySale  命名空间: Sale.SvrPySale

 

public class SynchroConfigSerializerSectionHandler : System.Configuration.IConfigurationSectionHandler
{
        public object Create(object parent, object configContext, System.Xml.XmlNode section) { return section; }
}

 =================================================================================

获取代码:

XmlNode xmlUrl = System.Configuration.ConfigurationManager.GetSection("updateurl") as XmlNode;

 

Type:

System.Configuration.SingleTagSectionHandler
System.Configuration.DictionarySectionHandler
System.Configuration.NameValueSectionHandler

 

备忘!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值