語言

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 程式碼。

以下是設定檔 provider 及其 eventMappings 章節的節錄。 它們預設已經設定好了。 你唯一需要做的就是提供該區域中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 健康監控讓生產與營運人員能管理已部署的網頁應用程式。 System.Web.Management命名空間包含負責包裝應用程式健康狀態資料的健康事件類型,以及負責處理這些資料的提供者類型。 同時也包含協助健康事件管理的支援類型。

以下列表描述了 ASP.NET 會引發類型為 WebAuthenticationSuccessAuditEvent 的特徵。

Note

預設情況下,ASP.NET 僅設定為記錄稽核失敗條件,因為日誌成功條件會嚴重消耗系統資源。 你也可以設定系統記錄成功條件。

  • 表單認證。 成功的條件會被審核。 成功稽核會包含被驗證的使用者名稱。 相反地,失敗稽核不會包含使用者名稱,因為這通常是因為解密或驗證失敗的工單所致。 兩者都包含用戶端的 IP 位址。 相關的事件稽核代碼為 AuditFormsAuthenticationSuccess。

  • 會員資格。 成功的條件會被審核。 成功與失敗審核都會包含嘗試的使用者名稱。 這兩種形式的稽核都不會包含嘗試過的密碼,因為那會讓日誌中存續有效密碼的風險。 相關的事件稽核代碼為 AuditMembershipAuthenticationSuccess。

當 a WebAuthenticationSuccessAuditEvent 被提出時,預設會更新 Authentication Success Events Raised Performance 計數器。 要在系統監控器(PerfMon)中查看此效能計數器,在新增計數器視窗中,請在Performance object下拉選單中選擇ASP.NET,選擇認證成功事件 Raised Performance 計數器,並點擊 Add按鈕。 欲了解更多資訊,請參閱 使用 System Monitor (PerfMon) with ASP.NET Applications。

Note

大多數情況下,你可以依實作使用 ASP.NET 健康監控類型,並且透過在 healthMonitoring 配置區塊指定數值來控制健康監控系統。 你也可以從健康監控類型中衍生,建立屬於自己的活動和服務提供者。 關於從該 WebBaseEvent 類別推導的範例,請參見本主題中的範例。

建構函式

名稱 Description
WebAuthenticationSuccessAuditEvent(String, Object, Int32, Int32, String)

使用提供的參數初始化類別 WebSuccessAuditEvent 。

WebAuthenticationSuccessAuditEvent(String, Object, Int32, String)

使用提供的參數初始化類別 WebAuthenticationSuccessAuditEvent 。

屬性

名稱 Description
EventCode

取得與事件相關的程式碼值。

(繼承來源 WebBaseEvent)
EventDetailCode

取得事件細節代碼。

(繼承來源 WebBaseEvent)
EventID

取得與事件相關的識別碼。

(繼承來源 WebBaseEvent)
EventOccurrence

會獲得一個代表事件發生次數的計數器。

(繼承來源 WebBaseEvent)
EventSequence

讀取該事件被應用程式提出的次數。

(繼承來源 WebBaseEvent)
EventSource

獲得能引發事件的物件。

(繼承來源 WebBaseEvent)
EventTime

取得事件被提出的時間。

(繼承來源 WebBaseEvent)
EventTimeUtc

取得事件被提出的時間。

(繼承來源 WebBaseEvent)
Message

收到描述事件的訊息。

(繼承來源 WebBaseEvent)
NameToAuthenticate

取得已認證使用者的名稱。

ProcessInformation

取得有關 ASP.NET 應用程式託管流程的資訊。

(繼承來源 WebManagementEvent)
RequestInformation

取得與網路請求相關的資訊。

(繼承來源 WebAuditEvent)

方法

名稱 Description
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
FormatCustomEventDetails(WebEventFormatter)

提供活動資訊的標準格式。

(繼承來源 WebBaseEvent)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type。

(繼承來源 Object)
IncrementPerfCounters()

增加審計成功事件、提升績效計數。

(繼承來源 WebSuccessAuditEvent)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
Raise()

透過通知任何已設定的提供者事件已發生,從而提出事件。

(繼承來源 WebBaseEvent)
ToString()

格式化活動資訊以供展示用途。

(繼承來源 WebBaseEvent)
ToString(Boolean, Boolean)

格式化活動資訊以供展示用途。

(繼承來源 WebBaseEvent)

適用於

另請參閱