2009-11-06 42 views
2

我已經建立了ASP.Net健康監測在web.config中:訪問HealthMonitoring提供者設定編程

<healthMonitoring enabled="true"> 
<providers> 
<clear /> 
<add name="CriticalMailEventProvider" type="System.Web.Management.SimpleMailWebEventProvider" 
from="[email protected]" to="[email protected]" 
bodyHeader="Application Error!" bodyFooter="Please investigate ASAP." 
subjectPrefix="ERROR: " buffer="true" bufferMode="Critical Notification" 
maxEventLength="8192" maxMessagesPerNotification="1" 
/> 
</providers></healthMonitoring> 

而且我試圖讀取該供應商的配置代碼:

Dim HealthMonitoring As System.Web.Configuration.HealthMonitoringSection 
Dim ToAddress As String 
HealthMonitoring = CType(WebConfigurationManager.GetWebApplicationSection("system.web/healthMonitoring"), HealthMonitoringSection) 
ToAddress = HealthMonitoring.Providers(0).ElementInformation.Properties("to").Value.ToString 

[注意:不是實際的產品代碼,爲了簡明起見硬編碼&]
問題:儘管ElementInformation.Properties集合包含如預期的那樣,值是「Nothing」,「Properties(」to「)」的所有其他屬性也是如此。
如何訪問提供程序的設置?

+0

anysolution,任何樣品完整的代碼? – Kiquenet 2011-01-24 15:45:48

回答

3

在C#:

HealthMonitoringSection section = WebConfigurationManager.GetWebApplicationSection("system.web/healthMonitoring") as HealthMonitoringSection; 

section.Providers [3] .Parameters [ 「到」]返回[email protected]

(3假定供應商名單並沒有在web.config中清除。)

+0

我確定我嘗試了參數集合,但它現在可以工作,歡呼聲。 – AUSteve 2010-01-07 00:29:43

0

我使出讀取web.config文件爲一個XML文檔,並使用與XPath的選擇節點:基於AUSteve的配置/ System.Web程序/ healthMonitoring /供應商/ * [@名稱]

0

回答我用下面的代碼。

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 
相關問題