WebAuthenticationFailureAuditEvent 类

定义

提供有关 ASP.NET 身份验证失败的信息。

public ref class WebAuthenticationFailureAuditEvent : System::Web::Management::WebFailureAuditEvent
public class WebAuthenticationFailureAuditEvent : System.Web.Management.WebFailureAuditEvent
type WebAuthenticationFailureAuditEvent = class
    inherit WebFailureAuditEvent
Public Class WebAuthenticationFailureAuditEvent
Inherits WebFailureAuditEvent
继承

示例

下面的代码示例演示如何使用 WebAuthenticationFailureAuditEvent 类。


using System;
using System.Text;
using System.Web;
using System.Web.Management;

namespace SamplesAspNet
{
    // Implements a custom WebAuthenticationFailureAuditEvent class. 
    public class SampleWebAuthenticationFailureAuditEvent : 
        System.Web.Management.WebAuthenticationFailureAuditEvent
    {
        private string customCreatedMsg, customRaisedMsg;

        // Invoked in case of events identified only by 
        // their event code.
        public SampleWebAuthenticationFailureAuditEvent(
            string msg, object eventSource, 
            int eventCode, string userName):
        base(msg, eventSource, eventCode, userName)
        {
            // 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 SampleWebAuthenticationFailureAuditEvent(
            string msg, object eventSource,
            int eventCode, int detailedCode, string userName):
        base(msg, eventSource, eventCode, detailedCode, userName)
        {
            // Perform custom initialization.
            customCreatedMsg =
            string.Format("Event created at: {0}",
                DateTime.Now.TimeOfDay.ToString());
        }


        // Raises the SampleWebAuthenticationFailureAuditEvent.
        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(
                "* SampleWebAuthenticationFailureAuditEvent 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(
                "* SampleWebAuthenticationFailureAuditEvent End *");

            formatter.IndentationLevel -= 1;
        }
    }
}
Imports System.Text
Imports System.Web
Imports System.Web.Management


' Implements a custom WebAuthenticationFailureAuditEvent class. 

Public Class SampleWebAuthenticationFailureAuditEvent
    Inherits System.Web.Management.WebAuthenticationFailureAuditEvent
    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, _
    ByVal userName As String)
        MyBase.New(msg, eventSource, eventCode, userName)
        ' 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, _
    ByVal userName As String)
        MyBase.New(msg, eventSource, eventCode, _
        detailedCode, userName)
        ' Perform custom initialization.
        customCreatedMsg = _
        String.Format( _
        "Event created at: {0}", DateTime.Now.TimeOfDay.ToString())

    End Sub



    ' Raises the SampleWebAuthenticationFailureAuditEvent.
    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( _
        "* SampleWebAuthenticationFailureAuditEvent 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( _
        "* SampleWebAuthenticationFailureAuditEvent End *")

        formatter.IndentationLevel -= 1

    End Sub
End Class

注解

以下列表描述了默认由 ASP.NET 引发事件的功能 WebAuthenticationFailureAuditEvent

注意

默认情况下,ASP.NET 配置为仅记录审核失败情况,因为日志记录成功条件可能会严重给系统资源造成压力。 始终可以将系统配置为记录成功条件。

  • 表单身份验证。 虽然成功审核包括经过身份验证的用户名;失败审核不包括用户名,因为它们通常由未通过解密或验证的票证导致的。 两者都包含客户端 IP 地址。 相关的事件审核代码为 AuditFormsAuthenticationFailure

  • 会员。 成功和失败审核都包含尝试的用户名。 这两种审核形式都不会包含尝试的密码,因为这将有可能在日志中保留有效的密码。 相关的事件审核代码为 AuditMembershipAuthenticationFailure

WebAuthenticationFailureAuditEvent引发 时,默认情况下会更新审核身份验证失败事件引发的性能计数器。 若要在系统监视器 (PerfMon) 中查看此性能计数器,请在“添加计数器”窗口中选择“ASP.NET性能对象”下拉列表中的“身份验证失败事件引发的性能”计数器,然后单击“添加”按钮。 有关详细信息,请参阅 将系统监视器 (PerfMon) 与 ASP.NET 应用程序配合使用

注意

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

构造函数

WebAuthenticationFailureAuditEvent(String, Object, Int32, Int32, String)

使用指定的事件参数对 WebAuthenticationFailureAuditEvent 类的新实例进行初始化。

WebAuthenticationFailureAuditEvent(String, Object, Int32, String)

使用指定的事件参数对 WebAuthenticationFailureAuditEvent 类的新实例进行初始化。

属性

EventCode

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

(继承自 WebBaseEvent)
EventDetailCode

获取事件详细信息代码。

(继承自 WebBaseEvent)
EventID

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

(继承自 WebBaseEvent)
EventOccurrence

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

(继承自 WebBaseEvent)
EventSequence

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

(继承自 WebBaseEvent)
EventSource

获取引发事件的对象。

(继承自 WebBaseEvent)
EventTime

获取引发事件的时间。

(继承自 WebBaseEvent)
EventTimeUtc

获取引发事件的时间。

(继承自 WebBaseEvent)
Message

获取描述事件的消息。

(继承自 WebBaseEvent)
NameToAuthenticate

获取要验证的用户名。

ProcessInformation

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

(继承自 WebManagementEvent)
RequestInformation

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

(继承自 WebAuditEvent)

方法

Equals(Object)

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

(继承自 Object)
FormatCustomEventDetails(WebEventFormatter)

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

(继承自 WebBaseEvent)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
IncrementPerfCounters()

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

(继承自 WebFailureAuditEvent)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
Raise()

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

(继承自 WebBaseEvent)
ToString()

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

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

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

(继承自 WebBaseEvent)

适用于

另请参阅