(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
备忘!