WebFailureAuditEvent 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供有關安全失效的資訊。
public ref class WebFailureAuditEvent : System::Web::Management::WebAuditEvent
public class WebFailureAuditEvent : System.Web.Management.WebAuditEvent
type WebFailureAuditEvent = class
inherit WebAuditEvent
Public Class WebFailureAuditEvent
Inherits WebAuditEvent
- 繼承
- 衍生
範例
以下程式碼範例示範如何從 WebFailureAuditEvent 類別衍生出自訂稽核事件。
using System;
using System.Text;
using System.Web;
using System.Web.Management;
namespace SamplesAspNet
{
// Implements a custom WebFailureAuditEvent class.
public class SampleWebFailureAuditEvent :
System.Web.Management.WebFailureAuditEvent
{
private string customCreatedMsg, customRaisedMsg;
// Invoked in case of events identified only by their event code.
public SampleWebFailureAuditEvent(string msg, object eventSource,
int eventCode):
base(msg, eventSource, eventCode)
{
// Perform custom initialization.
customCreatedMsg =
string.Format("Event created at: {0}",
DateTime.Now.TimeOfDay.ToString());
}
// Invoked in case of events identified by their event code and
// event detailed code.
public SampleWebFailureAuditEvent(string msg, object eventSource,
int eventCode, int detailedCode):
base(msg, eventSource, eventCode, detailedCode)
{
// Perform custom initialization.
customCreatedMsg =
string.Format("Event created at: {0}",
DateTime.Now.TimeOfDay.ToString());
}
// Raises the SampleWebFailureAuditEvent.
public override void Raise()
{
// Perform custom processing.
customRaisedMsg =
string.Format("Event raised at: {0}",
DateTime.Now.TimeOfDay.ToString());
// Raise the event.
WebBaseEvent.Raise(this);
}
// Obtains the current thread information.
public WebRequestInformation GetRequestInformation()
{
// No customization is allowed.
return RequestInformation;
}
//Formats Web request event information.
//This method is invoked indirectly by the provider
//using one of the overloaded ToString methods.
public override void FormatCustomEventDetails(WebEventFormatter formatter)
{
base.FormatCustomEventDetails(formatter);
// Add custom data.
formatter.AppendLine("");
formatter.IndentationLevel += 1;
formatter.AppendLine(
"******** SampleWebFailureAuditEvent Start ********");
formatter.AppendLine(string.Format("Request path: {0}",
RequestInformation.RequestPath));
formatter.AppendLine(string.Format("Request Url: {0}",
RequestInformation.RequestUrl));
// Display custom event timing.
formatter.AppendLine(customCreatedMsg);
formatter.AppendLine(customRaisedMsg);
formatter.AppendLine(
"******** SampleWebFailureAuditEvent End ********");
formatter.IndentationLevel -= 1;
}
}
}
Imports System.Text
Imports System.Web
Imports System.Web.Management
' Implements a custom WebFailureAuditEvent class.
Public Class SampleWebFailureAuditEvent
Inherits System.Web.Management.WebFailureAuditEvent
Private customCreatedMsg, customRaisedMsg As String
' Invoked in case of events identified only by their event code.
Public Sub New(ByVal msg As String, _
ByVal eventSource As Object, ByVal eventCode As Integer)
MyBase.New(msg, eventSource, eventCode)
' Perform custom initialization.
customCreatedMsg = String.Format("Event created at: {0}", _
DateTime.Now.TimeOfDay.ToString())
End Sub
' Invoked in case of events identified by their event code and
' event detailed code.
Public Sub New(ByVal msg As String, ByVal eventSource As Object, _
ByVal eventCode As Integer, ByVal detailedCode As Integer)
MyBase.New(msg, eventSource, eventCode, detailedCode)
' Perform custom initialization.
customCreatedMsg = String.Format("Event created at: {0}", _
DateTime.Now.TimeOfDay.ToString())
End Sub
' Raises the SampleWebFailureAuditEvent.
Public Overrides Sub Raise()
' Perform custom processing.
customRaisedMsg = String.Format("Event raised at: {0}", _
DateTime.Now.TimeOfDay.ToString())
' Raise the event.
WebBaseEvent.Raise(Me)
End Sub
' Obtains the current thread information.
Public Function GetRequestInformation() As WebRequestInformation
' No customization is allowed.
Return RequestInformation
End Function 'GetRequestInformation
'Formats Web request event information.
'This method is invoked indirectly by the provider
'using one of the overloaded ToString methods.
Public Overrides Sub FormatCustomEventDetails(ByVal formatter _
As WebEventFormatter)
MyBase.FormatCustomEventDetails(formatter)
' Add custom data.
formatter.AppendLine("")
formatter.IndentationLevel += 1
formatter.AppendLine("******** SampleWebFailureAuditEvent Start ********")
formatter.AppendLine(String.Format("Request path: {0}", _
RequestInformation.RequestPath))
formatter.AppendLine(String.Format("Request Url: {0}", _
RequestInformation.RequestUrl))
' Display custom event timing.
formatter.AppendLine(customCreatedMsg)
formatter.AppendLine(customRaisedMsg)
formatter.AppendLine("******** SampleWebFailureAuditEvent End ********")
formatter.IndentationLevel -= 1
End Sub
End Class
以下設定摘錄展示了如何啟用 ASP.NET 使用 WebFailureAuditEvent 事件。
<healthMonitoring
enabled="true"
heartBeatInterval="0">
<providers>
<add name="EventLogProvider"
type="System.Web.Management.EventLogWebEventProvider,
System.Web,Version=2.0.3600.0,Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
<eventMappings>
<add name="SampleWebFailureAuditEvent"
type="SamplesAspNet.SampleWebFailureAuditEvent,
webfailureauditevent,Version=1.0.1663.31140,
Culture=neutral,
PublicKeyToken=0d1fa0f69d94de96,
processorArchitecture=MSIL"/>
</eventMappings>
<rules>
<add name="Custom Failure Audit Default"
eventName=" SampleWebFailureAuditEvent "
provider="EventLogProvider"
profile="Default"/>
</rules>
</healthMonitoring>
備註
ASP.NET 健康監控讓生產與營運人員能管理已部署的網頁應用程式。 System.Web.Management命名空間包含負責包裝應用程式健康狀態資料的健康事件類型,以及負責處理這些資料的提供者類型。 同時也包含協助健康事件管理的支援類型。
當安全操作失敗時,會 WebFailureAuditEvent 使用此類別。 例如網頁請求的 URL 授權失敗。
預設情況下,ASP.NET 設定為針對以下功能啟動 WebFailureAuditEvent 事件:
申請授權。 ASP.NET 僅在請求中關聯到 Windows 身份時才嘗試檔案授權。 相關的事件稽核代碼為 AuditFileAuthorizationFailure。
網址授權。 這規範了未經授權存取 URL 資源的行為。 匿名使用者嘗試失敗不會被稽核,因為匿名驗證失敗在大多數情況下是可接受的。 相關的事件稽核代碼為 AuditUrlAuthorizationFailure。
一般未處理或安全未處理狀況。 以下是與這些條件相關的事件代碼列表:
當 WebFailureAuditEvent 事件被提出時,ASP.NET 健康監控會增加相關的稽核失敗事件 Raised 效能計數器,然後檢查 healthMonitoring 設定區塊,以判斷是否有提供者訂閱該事件。 若提供者訂閱事件,ASP.NET 會將事件派遣給他們處理。
Note
要在系統監控器(PerfMon)中查看審計失敗事件被提升的效能計數器,在
Note
大多數情況下,你可以依實作使用 ASP.NET 健康監控類型,並且透過在 healthMonitoring 配置區塊指定數值來控制健康監控系統。 你也可以從健康監控類型中衍生,建立屬於自己的活動和服務提供者。 關於從類別 WebFailureAuditEvent 推導的範例,請參見範例章節。
給繼承者的注意事項
在格式化自訂事件資訊以供顯示時,請覆蓋方法本身 FormatCustomEventDetails(WebEventFormatter) ,而非方法本身 ToString 。 這樣可以避免覆蓋或竄改敏感系統資訊。
建構函式
| 名稱 | Description |
|---|---|
| WebFailureAuditEvent(String, Object, Int32, Int32) |
使用所提供的參數初始化該類別的新實例 WebFailureAuditEvent 。 |
| WebFailureAuditEvent(String, Object, Int32) |
使用所提供的參數初始化該類別的新實例 WebFailureAuditEvent 。 |
屬性
| 名稱 | Description |
|---|---|
| EventCode |
取得與事件相關的程式碼值。 (繼承來源 WebBaseEvent) |
| EventDetailCode |
取得事件細節代碼。 (繼承來源 WebBaseEvent) |
| EventID |
取得與事件相關的識別碼。 (繼承來源 WebBaseEvent) |
| EventOccurrence |
會獲得一個代表事件發生次數的計數器。 (繼承來源 WebBaseEvent) |
| EventSequence |
讀取該事件被應用程式提出的次數。 (繼承來源 WebBaseEvent) |
| EventSource |
獲得能引發事件的物件。 (繼承來源 WebBaseEvent) |
| EventTime |
取得事件被提出的時間。 (繼承來源 WebBaseEvent) |
| EventTimeUtc |
取得事件被提出的時間。 (繼承來源 WebBaseEvent) |
| Message |
收到描述事件的訊息。 (繼承來源 WebBaseEvent) |
| ProcessInformation |
取得有關 ASP.NET 應用程式託管流程的資訊。 (繼承來源 WebManagementEvent) |
| RequestInformation |
取得與網路請求相關的資訊。 (繼承來源 WebAuditEvent) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| FormatCustomEventDetails(WebEventFormatter) |
提供活動資訊的標準格式。 (繼承來源 WebBaseEvent) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IncrementPerfCounters() |
增加審計失敗事件提升績效計數。 |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| Raise() |
透過通知任何已設定的提供者事件已發生,從而提出事件。 (繼承來源 WebBaseEvent) |
| ToString() |
格式化活動資訊以供展示用途。 (繼承來源 WebBaseEvent) |
| ToString(Boolean, Boolean) |
格式化活動資訊以供展示用途。 (繼承來源 WebBaseEvent) |