ServiceSecurityAuditBehavior 類別

定義

指定安全性事件的稽核行為。 一般而言,安全性事件是由如傳輸、訊息或交涉驗證和授權事件的驗證事件所組成。 如需詳細資訊,請參閱ServiceAuthorizationManager

public ref class ServiceSecurityAuditBehavior sealed : System::ServiceModel::Description::IServiceBehavior
public sealed class ServiceSecurityAuditBehavior : System.ServiceModel.Description.IServiceBehavior
type ServiceSecurityAuditBehavior = class
    interface IServiceBehavior
Public NotInheritable Class ServiceSecurityAuditBehavior
Implements IServiceBehavior
繼承
ServiceSecurityAuditBehavior
實作

範例

下列程式碼會建立 ServiceHost 類別的執行個體,並且將 ServiceSecurityAuditBehavior 新增至其行為集合。

public static void Main()
{
    // Get base address from appsettings in configuration.
    Uri baseAddress = new Uri(ConfigurationManager.
        AppSettings["baseAddress"]);

    // Create a ServiceHost for the CalculatorService type
    // and provide the base address.
    using (ServiceHost serviceHost = new
        ServiceHost(typeof(CalculatorService), baseAddress))
    {
        // Create a new auditing behavior and set the log location.
        ServiceSecurityAuditBehavior newAudit =
            new ServiceSecurityAuditBehavior();
        newAudit.AuditLogLocation =
            AuditLogLocation.Application;
        newAudit.MessageAuthenticationAuditLevel =
            AuditLevel.SuccessOrFailure;
        newAudit.ServiceAuthorizationAuditLevel =
            AuditLevel.SuccessOrFailure;
        newAudit.SuppressAuditFailure = false;
        // Remove the old behavior and add the new.
        serviceHost.Description.
            Behaviors.Remove<ServiceSecurityAuditBehavior>();
        serviceHost.Description.Behaviors.Add(newAudit);
        // Open the ServiceHostBase to create listeners
        // and start listening for messages.
        serviceHost.Open();

        // The service can now be accessed.
        Console.WriteLine("The service is ready.");
        Console.WriteLine("Press <ENTER> to terminate service.");
        Console.WriteLine();
        Console.ReadLine();

        // Close the ServiceHostBase to shutdown the service.
        serviceHost.Close();
    }
}
Public Shared Sub Main() 
    ' Get base address from appsettings in configuration.
    Dim baseAddress As New Uri(ConfigurationManager.AppSettings("baseAddress"))
    
    ' Create a ServiceHost for the CalculatorService type 
    ' and provide the base address.
    Dim serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)
    Try
        ' Create a new auditing behavior and set the log location.
        Dim newAudit As New ServiceSecurityAuditBehavior()
        newAudit.AuditLogLocation = AuditLogLocation.Application
        newAudit.MessageAuthenticationAuditLevel = _
            AuditLevel.SuccessOrFailure
        newAudit.ServiceAuthorizationAuditLevel = _
            AuditLevel.SuccessOrFailure
        newAudit.SuppressAuditFailure = False
        ' Remove the old behavior and add the new.
        serviceHost.Description.Behaviors.Remove(Of ServiceSecurityAuditBehavior)
        serviceHost.Description.Behaviors.Add(newAudit)
        ' Open the ServiceHostBase to create listeners 
        ' and start listening for messages.
        serviceHost.Open()
        
        ' The service can now be accessed.
        Console.WriteLine("The service is ready.")
        Console.WriteLine("Press <ENTER> to terminate service.")
        Console.WriteLine()
        Console.ReadLine()
        
        ' Close the ServiceHostBase to shutdown the service.
        serviceHost.Close()
    Finally
    End Try

End Sub

備註

類別 ServiceSecurityAuditBehavior 可用來稽核 Windows Communication Foundation (WCF) 驗證事件。 啟用稽核時,可以稽核成功或失敗的驗證嘗試 (或兩者)。 事件會寫入三個事件記錄檔之一:應用程式、安全性或作業系統版本的預設記錄檔。 使用 Windows 事件檢視器,即可檢視所有的事件記錄。

您可以使用這個類別來指定要將事件記錄寫入哪個記錄檔,以及要寫入的驗證事件的種類。 此外,您也可以將 SuppressAuditFailure 屬性設定為 false (預設為 true) 以指定是否隱藏稽核失敗。

如需有關稽核 WCF 應用程式安全性事件的詳細資訊,請參閱 稽核

若要在組態中指定稽核行為,請使用< serviceSecurityAudit >

建構函式

ServiceSecurityAuditBehavior()

初始化 ServiceSecurityAuditBehavior 類別的新執行個體。

屬性

AuditLogLocation

取得或設定寫入安全性相關事件記錄的位置。

MessageAuthenticationAuditLevel

取得或設定要在訊息層級稽核的驗證事件類型。

ServiceAuthorizationAuditLevel

取得或設定要在服務層級稽核的授權事件類型。

SuppressAuditFailure

取得或設定值,這個值表示稽核失敗是否影響應用程式。

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

IServiceBehavior.AddBindingParameters(ServiceDescription, ServiceHostBase, Collection<ServiceEndpoint>, BindingParameterCollection)

將自訂資料傳遞至繫結項目,以支援合約實作。

IServiceBehavior.ApplyDispatchBehavior(ServiceDescription, ServiceHostBase)

提供功能以變更執行階段屬性值或插入自訂延伸物件,例如錯誤處理常式、訊息或參數攔截器、安全性延伸或其他自訂延伸物件。

IServiceBehavior.Validate(ServiceDescription, ServiceHostBase)

未實作。

適用於