Asp.net 以编程方式访问HealthMonitoring提供程序设置
我已在web.config中设置了ASP.Net运行状况监视:Asp.net 以编程方式访问HealthMonitoring提供程序设置,asp.net,configuration,health-monitoring,Asp.net,Configuration,Health Monitoring,我已在web.config中设置了ASP.Net运行状况监视: <healthMonitoring enabled="true"> <providers> <clear /> <add name="CriticalMailEventProvider" type="System.Web.Management.SimpleMailWebEventProvider" from="appErrors@myhost.com" to="me@myhost.com"
<healthMonitoring enabled="true">
<providers>
<clear />
<add name="CriticalMailEventProvider" type="System.Web.Management.SimpleMailWebEventProvider"
from="appErrors@myhost.com" to="me@myhost.com"
bodyHeader="Application Error!" bodyFooter="Please investigate ASAP."
subjectPrefix="ERROR: " buffer="true" bufferMode="Critical Notification"
maxEventLength="8192" maxMessagesPerNotification="1"
/>
</providers></healthMonitoring>
[注:非实际生产代码,为简洁起见,硬编码和压缩]问题:当ElementInformation.Properties集合按预期包含键时,值为“Nothing”,而“Properties(“to”)的所有其他属性也是如此
如何访问提供者的设置?我将web.config文件作为XML文档读取,并使用XPath:configuration/system.web/healthMonitoring/providers/*[@name]根据AUSteve的回答,我使用了以下代码
Dim xmldoc As New System.Xml.XmlDocument
xmldoc.Load(HttpContext.Current.Server.MapPath("Web.config"))
Dim xmlnsManager As System.Xml.XmlNamespaceManager = New System.Xml.XmlNamespaceManager(xmldoc.NameTable)
xmlnsManager.AddNamespace("nc", "http://schemas.microsoft.com/.NetConfiguration/v2.0")
Dim emailTo As String = xmldoc.SelectSingleNode("/configuration/system.web/healthMonitoring/providers/add", xmlnsManager).Attributes("to").Value.ToString
在C#中:
节。提供程序[3]。参数[“到”]返回“me@myhost.com“
(3假设未在web.config中清除提供程序列表。)您可以使用Initialize方法访问在web.config中指定的属性。只需访问NameValueCollection(并在调用base.Initialize之前将其从自定义属性中删除)
这篇文章展示了一个C#实现:我肯定我尝试过参数集合,但现在它可以工作了,干杯。任何解决方案,有完整的代码示例吗?
Dim xmldoc As New System.Xml.XmlDocument
xmldoc.Load(HttpContext.Current.Server.MapPath("Web.config"))
Dim xmlnsManager As System.Xml.XmlNamespaceManager = New System.Xml.XmlNamespaceManager(xmldoc.NameTable)
xmlnsManager.AddNamespace("nc", "http://schemas.microsoft.com/.NetConfiguration/v2.0")
Dim emailTo As String = xmldoc.SelectSingleNode("/configuration/system.web/healthMonitoring/providers/add", xmlnsManager).Attributes("to").Value.ToString
HealthMonitoringSection section = WebConfigurationManager.GetWebApplicationSection("system.web/healthMonitoring") as HealthMonitoringSection;