app.config中的多个相同的自定义配置部分
|
我正在尝试在C#.NET控制台应用程序的app.config文件中创建自定义配置部分。它将存储有关某些服务器的一些详细信息,例如:
<configSections>
<sectionGroup name=\"serverGroup\">
<section name=\"server\" type=\"RPInstaller.ServerConfig\" allowLocation=\"true\" allowDefinition=\"Everywhere\"/>
</sectionGroup>
</configSections>
<serverGroup>
<server>
<name>rmso2srvm</name>
<isBatchServer>false</isBatchServer>
</server>
<server>
<name>rmsb2srvm</name>
<isBatchServer>true</isBatchServer>
</server>
</serverGroup>
我为服务器部分定义了一个类,如下所示:
namespace RPInstaller
{
public class ServerConfig : ConfigurationSection
{
[ConfigurationProperty(\"name\", IsRequired=true)]
public string Name {...}
[ConfigurationProperty(\"isBatchServer\", IsRequired = true)]
public bool IsBatchServer {...}
}
}
现在,当我尝试加载服务器节时,出现一个异常:\“节只能在每个配置文件中出现一次\”。
如何在我的app.config文件中合法定义多个服务器部分?
没有找到相关结果
已邀请:
2 个回复
孝箱捆讨
我以前是如何设置自定义部分的 要访问的VB代码:
博沮富教全
类,并将其添加到您的section类的定义中:
此处有更多信息: http://msdn.microsoft.com/zh-CN/library/2tw134k3.aspx