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 區段的摘錄。 預設已設定它們。 唯一需要做的是提供 區段中專案的 ruleshealthMonitoring 設定。

<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引發 時,預設會更新驗證成功事件引發效能計數器。 若要在 System Monitor (PerfMon) 中檢視此效能計數器,請在 [新增計數器] 視窗中,選取 [效能物件] 下拉式清單中的[ASP.NET],選取 [驗證成功事件引發效能計數器],然後按一下 [新增] 按鈕。 如需詳細資訊,請參閱 搭配 ASP.NET 應用程式使用 System Monitor (PerfMon)

注意

在大部分情況下,您將能夠使用實作 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)

適用於

另請參閱