WebFailureAuditEvent 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供有关安全故障的信息。
public ref class WebFailureAuditEvent : System::Web::Management::WebAuditEvent
public class WebFailureAuditEvent : System.Web.Management.WebAuditEvent
type WebFailureAuditEvent = class
inherit WebAuditEvent
Public Class WebFailureAuditEvent
Inherits WebAuditEvent
- 继承
- 派生
示例
下面的代码示例演示如何从 WebFailureAuditEvent 类派生以创建自定义审核事件。
using System;
using System.Text;
using System.Web;
using System.Web.Management;
namespace SamplesAspNet
{
// Implements a custom WebFailureAuditEvent class.
public class SampleWebFailureAuditEvent :
System.Web.Management.WebFailureAuditEvent
{
private string customCreatedMsg, customRaisedMsg;
// Invoked in case of events identified only by their event code.
public SampleWebFailureAuditEvent(string msg, object eventSource,
int eventCode):
base(msg, eventSource, eventCode)
{
// 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 SampleWebFailureAuditEvent(string msg, object eventSource,
int eventCode, int detailedCode):
base(msg, eventSource, eventCode, detailedCode)
{
// Perform custom initialization.
customCreatedMsg =
string.Format("Event created at: {0}",
DateTime.Now.TimeOfDay.ToString());
}
// Raises the SampleWebFailureAuditEvent.
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(
"******** SampleWebFailureAuditEvent 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(
"******** SampleWebFailureAuditEvent End ********");
formatter.IndentationLevel -= 1;
}
}
}
Imports System.Text
Imports System.Web
Imports System.Web.Management
' Implements a custom WebFailureAuditEvent class.
Public Class SampleWebFailureAuditEvent
Inherits System.Web.Management.WebFailureAuditEvent
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)
MyBase.New(msg, eventSource, eventCode)
' 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)
MyBase.New(msg, eventSource, eventCode, detailedCode)
' Perform custom initialization.
customCreatedMsg = String.Format("Event created at: {0}", _
DateTime.Now.TimeOfDay.ToString())
End Sub
' Raises the SampleWebFailureAuditEvent.
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("******** SampleWebFailureAuditEvent 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("******** SampleWebFailureAuditEvent End ********")
formatter.IndentationLevel -= 1
End Sub
End Class
以下配置摘录显示了如何启用 ASP.NET 以使用 WebFailureAuditEvent 事件。
<healthMonitoring
enabled="true"
heartBeatInterval="0">
<providers>
<add name="EventLogProvider"
type="System.Web.Management.EventLogWebEventProvider,
System.Web,Version=2.0.3600.0,Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
<eventMappings>
<add name="SampleWebFailureAuditEvent"
type="SamplesAspNet.SampleWebFailureAuditEvent,
webfailureauditevent,Version=1.0.1663.31140,
Culture=neutral,
PublicKeyToken=0d1fa0f69d94de96,
processorArchitecture=MSIL"/>
</eventMappings>
<rules>
<add name="Custom Failure Audit Default"
eventName=" SampleWebFailureAuditEvent "
provider="EventLogProvider"
profile="Default"/>
</rules>
</healthMonitoring>
注解
ASP.NET 运行状况监视允许生产和运营人员管理已部署的 Web 应用程序。 命名空间 System.Web.Management 包含负责打包应用程序运行状况数据的运行状况事件类型和负责处理此数据的提供程序类型。 它还包含支持类型,这些类型有助于管理运行状况事件。
当安全操作失败时,将使用 WebFailureAuditEvent 该类。 例如,Web 请求的 URL 授权失败。
默认情况下,ASP.NET 配置为针对以下功能引发 WebFailureAuditEvent 事件:
文件授权。 仅当Windows标识与请求关联时,ASP.NET 才会尝试文件授权。 相关事件审核代码为 AuditFileAuthorizationFailure.
URL 授权。 这将控制未经授权的访问 URL 资源的尝试。 匿名用户的失败尝试不会审核,因为在大多数情况下,匿名身份验证失败是可以接受的。 相关事件审核代码为 AuditUrlAuthorizationFailure.
常规未经处理的或未处理的安全的条件。 下面是与这些条件相关的事件代码的列表:
引发 WebFailureAuditEvent 事件时,ASP.NET 运行状况监视会递增相关的审核失败事件引发性能计数器,然后检查 healthMonitoring 配置部分以确定任何提供程序是否订阅事件。 如果提供程序订阅事件,ASP.NET 将事件调度给他们进行处理。
注释
若要查看Add Counters窗口中的“审核失败事件引发的性能计数器”,请参阅 从 Performance 对象下拉列表中选择 ASP.NET,选择 Audit Failure Events Raised performance counter, 然后单击 Add 按钮。
注释
在大多数情况下,你将能够使用实现的 ASP.NET 运行状况监视类型,并通过在 healthMonitoring 配置节中指定值来控制运行状况监视系统。 还可以从运行状况监视类型派生,以创建自己的自定义事件和提供程序。 有关从 WebFailureAuditEvent 类派生的示例,请参阅“示例”部分。
继承者说明
设置自定义事件信息的显示格式时,请重写 FormatCustomEventDetails(WebEventFormatter) 方法,而不是 ToString 方法。 这将避免覆盖或篡改敏感系统信息。
构造函数
| 名称 | 说明 |
|---|---|
| WebFailureAuditEvent(String, Object, Int32, Int32) |
使用提供的参数初始化类的新实例 WebFailureAuditEvent 。 |
| WebFailureAuditEvent(String, Object, Int32) |
使用提供的参数初始化类的新实例 WebFailureAuditEvent 。 |
属性
| 名称 | 说明 |
|---|---|
| EventCode |
获取与事件关联的代码值。 (继承自 WebBaseEvent) |
| EventDetailCode |
获取事件详细信息代码。 (继承自 WebBaseEvent) |
| EventID |
获取与事件关联的标识符。 (继承自 WebBaseEvent) |
| EventOccurrence |
获取一个计数器,该计数器表示事件发生的次数。 (继承自 WebBaseEvent) |
| EventSequence |
获取应用程序引发事件的次数。 (继承自 WebBaseEvent) |
| EventSource |
获取引发事件的对象。 (继承自 WebBaseEvent) |
| EventTime |
获取引发事件的时间。 (继承自 WebBaseEvent) |
| EventTimeUtc |
获取引发事件的时间。 (继承自 WebBaseEvent) |
| Message |
获取描述事件的消息。 (继承自 WebBaseEvent) |
| ProcessInformation |
获取有关 ASP.NET 应用程序托管过程的信息。 (继承自 WebManagementEvent) |
| RequestInformation |
获取与 Web 请求关联的信息。 (继承自 WebAuditEvent) |
方法
| 名称 | 说明 |
|---|---|
| Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
| FormatCustomEventDetails(WebEventFormatter) |
提供事件信息的标准格式。 (继承自 WebBaseEvent) |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| IncrementPerfCounters() |
递增审核失败事件引发的性能计数器。 |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| Raise() |
通过通知任何配置的提供程序已发生事件来引发事件。 (继承自 WebBaseEvent) |
| ToString() |
设置用于显示目的的事件信息的格式。 (继承自 WebBaseEvent) |
| ToString(Boolean, Boolean) |
设置用于显示目的的事件信息的格式。 (继承自 WebBaseEvent) |