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)

未实现。

适用于