WebFailureAuditEvent 类

定义

提供有关安全失败的信息。

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 运行状况监视允许生产和运营人员管理已部署的 Web 应用程序。 命名空间 System.Web.Management 包含负责打包应用程序运行状况状态数据的运行状况事件类型和负责处理此数据的提供程序类型。 它还包含有助于管理运行状况事件的支持类型。

安全 WebFailureAuditEvent 操作失败时使用 类。 其中一个示例是 Web 请求的 URL 授权失败。

默认情况下,ASP.NET 配置为针对以下功能引发 WebFailureAuditEvent 事件:

WebFailureAuditEvent引发事件时,ASP.NET 运行状况监视会递增相关的审核失败事件引发的性能计数器,然后检查healthMonitoring配置部分以确定是否有任何提供程序订阅该事件。 如果提供程序订阅事件,ASP.NET 将事件调度给他们进行处理。

注意

若要查看系统监视器 (PerfMon) 中的审核失败事件引发性能计数器,请在“添加计数器”窗口中,从“性能对象”下拉列表中选择“ASP.NET”,选择“审核失败事件引发的性能”计数器,然后单击“添加”按钮。

注意

在大多数情况下,你将能够使用实现的 ASP.NET 运行状况监视类型,并通过在 healthMonitoring 配置部分中指定值来控制运行状况监视系统。 还可以从运行状况监视类型派生,以创建自己的自定义事件和提供程序。 有关从 WebFailureAuditEvent 类派生的示例,请参阅示例部分。

继承者说明

设置自定义事件信息的格式以供显示时,请重写 FormatCustomEventDetails(WebEventFormatter) 方法,而不是 ToString 方法。 这将避免覆盖或篡改敏感系统信息。

构造函数

WebFailureAuditEvent(String, Object, Int32)

使用所提供的参数初始化 WebFailureAuditEvent 类的新实例。

WebFailureAuditEvent(String, Object, Int32, Int32)

使用所提供的参数初始化 WebFailureAuditEvent 类的新实例。

属性

EventCode

获取与该事件关联的代码值。

(继承自 WebBaseEvent)
EventDetailCode

获取事件详细信息代码。

(继承自 WebBaseEvent)
EventID

获取与事件关联的标识符。

(继承自 WebBaseEvent)
EventOccurrence

获取表示事件发生次数的计数器。

(继承自 WebBaseEvent)
EventSequence

获取应用程序已引发事件的次数。

(继承自 WebBaseEvent)
EventSource

获取引发事件的对象。

(继承自 WebBaseEvent)
EventTime

获取引发事件的时间。

(继承自 WebBaseEvent)
EventTimeUtc

获取引发事件的时间。

(继承自 WebBaseEvent)
Message

获取描述事件的消息。

(继承自 WebBaseEvent)
ProcessInformation

获取有关 ASP.NET 应用程序承载进程的信息。

(继承自 WebManagementEvent)
RequestInformation

获取与该 Web 请求关联的信息。

(继承自 WebAuditEvent)

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
FormatCustomEventDetails(WebEventFormatter)

提供事件信息的标准格式设置。

(继承自 WebBaseEvent)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
IncrementPerfCounters()

递增“引发的审核失败事件”性能计数器。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
Raise()

通过将事件已发生这一情况通知任何已配置的提供程序来引发事件。

(继承自 WebBaseEvent)
ToString()

为显示而对事件信息进行格式化。

(继承自 WebBaseEvent)
ToString(Boolean, Boolean)

为显示而对事件信息进行格式化。

(继承自 WebBaseEvent)

适用于

另请参阅