【发布时间】:2010-11-12 13:59:41
【问题描述】:
我想创建一个自定义配置部分来处理电子邮件通知。配置需要采用以下格式:
<configSections>
<sectionGroup name="notifications">
<section name="notification" type="NotificationConfiguration" allowLocation="true" allowDefinition="Everywhere" />
</sectionGroup>
</configSections>
...
<notifications>
<notification name="..." enabled="..." delayInMinutes="...">
<recipients>
<add email="..." />
<add email="..." />
<add email="..." />
</recipients>
</notification>
<notification name="..." enabled="..." delayInMinutes="...">
<recipients>
<add email="..." />
<add email="..." />
<add email="..." />
</recipients>
</notification>
</notifications>
...
我可以使用NotificationConfiguration config = (NotificationConfiguration) ConfigurationManager.GetSection("notifications\notification") 使其正常工作,但这仅适用于一个<notification> 元素。如何完成多个元素以容纳多个通知?
处理这个的类比较长,这里就不贴了,但是可以从这里下载:
http://files.getdropbox.com/u/288235/NotificationConfiguration.cs
谢谢。
【问题讨论】:
-
您可以创建一个
外部元素,然后将所有通知元素放入该组中。这样,您将能够实现您想要实现的目标。 -
检查我更新的答案。
标签: asp.net configuration web-config