WebAuthenticationSuccessAuditEvent 类

定义

提供有关成功身份验证事件的信息。

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

示例

此代码示例包含两个部分:配置文件摘录,后跟演示如何自定义 WebAuthenticationSuccessAuditEvent 事件的代码。

下面是配置文件 providereventMappings 部分的摘录。 默认情况下,它们已设置。 唯一需要做的就是为 rules 节中的 healthMonitoring 元素提供设置。

<healthMonitoring
  enabled="true"
  heartBeatInterval="0">

    <providers>
      // Configure the provider to process
      // the health events.
      <add name="EventLogProvider"
         type="System.Web.Management.EventLogWebEventProvider,
         System.Web,Version=2.0.3600.0,Culture=neutral,
         PublicKeyToken=b03f5f7f11d50a3a"/>
    </providers>

    <eventMappings>
       <clear />
       // Configure the custom event
       // to handle the audit events.
        <add name="SampleWebAuthenticationSuccessAuditEvent"
          type="SamplesAspNet.SampleWebAuthenticationSuccessAuditEvent,
          webauthsuccessaudit, Version=1.0.1735.23144, Culture=neutral,
          PublicKeyToken=dd969eda3f3f6ae1, processorArchitecture=MSIL" />

     </eventMappings>
     <rules>
       <clear/>
       // Establish the connection between custom event
       // and the provider that must process it.
      <add name="Log Authentication Success Audits"
        eventName="SampleWebAuthenticationFailureAuditEvent"
        provider="EventLogProvider"
        profile="Custom" />\
     </rules>

</healthMonitoring>

以下代码演示如何自定义 WebAuthenticationSuccessAuditEvent 事件。


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

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

        // Invoked in case of events identified only by their event code.
        public SampleWebAuthenticationSuccessAuditEvent(
            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 SampleWebAuthenticationSuccessAuditEvent(
            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 SampleWebAuthenticationSuccessAuditEvent.
        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(
                "* SampleWebAuthenticationSuccessAuditEvent 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(
                "* SampleWebAuthenticationSuccessAuditEvent End *");

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


' Implements a custom WebAuthenticationSuccessAuditEvent class. 

Public Class SampleWebAuthenticationSuccessAuditEvent
    Inherits System.Web.Management.WebAuthenticationSuccessAuditEvent
    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 SampleWebAuthenticationSuccessAuditEvent.
    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( _
        "* SampleWebAuthenticationSuccessAuditEvent 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( _
        "* SampleWebAuthenticationSuccessAuditEvent End *")

        formatter.IndentationLevel -= 1

    End Sub
End Class

注解

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

以下列表描述了 ASP.NET 引发类型为 WebAuthenticationSuccessAuditEvent 的事件的功能。

注释

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

  • 表单身份验证。 审核成功的条件。 成功审核包括经过身份验证的用户名。 相反,失败审核不包括用户名,因为它们通常是由于票证解密或验证失败。 两者都包含客户端 IP 地址。 相关事件审核代码为 AuditFormsAuthenticationSuccess.

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

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

注释

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

构造函数

名称 说明
WebAuthenticationSuccessAuditEvent(String, Object, Int32, Int32, String)

WebSuccessAuditEvent使用提供的参数初始化类。

WebAuthenticationSuccessAuditEvent(String, Object, Int32, String)

WebAuthenticationSuccessAuditEvent使用提供的参数初始化类。

属性

名称 说明
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()

递增审核成功事件引发的性能计数器。

(继承自 WebSuccessAuditEvent)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
Raise()

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

(继承自 WebBaseEvent)
ToString()

设置用于显示目的的事件信息的格式。

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

设置用于显示目的的事件信息的格式。

(继承自 WebBaseEvent)

适用于

另请参阅