WebRequestEvent 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
定義提供網路請求資訊的事件基底類別。
public ref class WebRequestEvent : System::Web::Management::WebManagementEvent
public class WebRequestEvent : System.Web.Management.WebManagementEvent
type WebRequestEvent = class
inherit WebManagementEvent
Public Class WebRequestEvent
Inherits WebManagementEvent
- 繼承
範例
以下程式碼範例說明如何從 WebRequestEvent 類別衍生出自訂事件。
using System;
using System.Text;
using System.Web;
using System.Web.Management;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SamplesAspNet
{
// Implements a custom WebRequestEvent.
public class SampleWebRequestEvent :
System.Web.Management.WebRequestEvent
{
private string customCreatedMsg,
customRaisedMsg;
// Invoked in case of events identified only
// by their event code.
public SampleWebRequestEvent(
string msg,
object eventSource, int eventCode):
base(msg, eventSource, eventCode)
{
// Perform custom initialization.
customCreatedMsg =
string.Format(
"Event created at: {0}",
EventTime.ToString());
}
// Invoked in case of events identified
// by their event code.and
// related event detailed code.
public SampleWebRequestEvent(string msg,
object eventSource, int eventCode,
int eventDetailCode):
base(msg, eventSource, eventCode,
eventDetailCode)
{
// Perform custom initialization.
customCreatedMsg =
string.Format(
"Event created at: {0}",
EventTime.ToString());
}
// Raises the SampleWebRequestEvent.
public override void Raise()
{
// Perform custom processing.
customRaisedMsg =
string.Format(
"Event raised at: {0}",
EventTime.ToString());
// Raise the event.
base.Raise();
}
//Formats Web request event information.
public override void FormatCustomEventDetails(
WebEventFormatter formatter)
{
// Add custom data.
formatter.AppendLine("");
formatter.IndentationLevel += 1;
formatter.AppendLine(
"* Custom Request Information Start *");
//// Display custom event timing.
formatter.AppendLine(customCreatedMsg);
formatter.AppendLine(customRaisedMsg);
formatter.AppendLine(
"* Custom Request Information End *");
formatter.IndentationLevel -= 1;
}
}
}
Imports System.Text
Imports System.Web
Imports System.Web.Management
Imports System.Web.UI
Imports System.Web.UI.WebControls
' Implements a custom WebRequestEvent.
Public Class SampleWebRequestEvent
Inherits System.Web.Management.WebRequestEvent
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}", _
EventTime.ToString())
End Sub
' Invoked in case of events identified
' by their event code.and
' related event detailed code.
Public Sub New(ByVal msg As String, _
ByVal eventSource As Object, _
ByVal eventCode As Integer, _
ByVal eventDetailCode As Integer)
MyBase.New(msg, eventSource, _
eventCode, eventDetailCode)
' Perform custom initialization.
customCreatedMsg = String.Format( _
"Event created at: {0}", _
EventTime.ToString())
End Sub
' Raises the SampleWebRequestEvent.
Public Overrides Sub Raise()
' Perform custom processing.
customRaisedMsg = String.Format( _
"Event raised at: {0}", _
EventTime.ToString())
' Raise the event.
MyBase.Raise()
End Sub
'Formats Web request event information.
Public Overrides Sub FormatCustomEventDetails( _
ByVal formatter As WebEventFormatter)
' Add custom data.
formatter.AppendLine("")
formatter.IndentationLevel += 1
formatter.AppendLine( _
"* Custom Request Information Start *")
'// Display custom event timing.
formatter.AppendLine(customCreatedMsg)
formatter.AppendLine(customRaisedMsg)
formatter.AppendLine( _
"* Custom Request Information End *")
formatter.IndentationLevel -= 1
End Sub
End Class
以下是讓 ASP.NET 能使用自訂事件的設定檔摘錄。
<healthMonitoring
enabled="true" heartBeatInterval="0">
<providers>
<!-- Define the custom provider that
processes custom Web request events. -->
<add name="SampleWebEventProvider"
type="SamplesAspNet.SampleEventProvider,webeventprovider,Version=1.0.1573.18094, Culture=neutral, PublicKeyToken=b5a57a9a9d487cf4, processorArchitecture=MSIL"/>
</providers>
<eventMappings>
<!-- Define the event source that
issues custom events. -->
<add name="SampleWebRequestEvent"
type="SamplesAspNet.SampleWebRequestEvent,webrequestevent,Version=1.0.1573.23947, Culture=neutral, PublicKeyToken=e717d983a78c8ddb, processorArchitecture=MSIL"/>
</eventMappings>
<rules>
<!-- Associate custom event with
related custom provider -->
<add
name="CustomWebRequestEvent"
eventName="SampleWebRequestEvent"
provider="SampleWebEventProvider"
profile="Critical"/>
</rules>
</healthMonitoring>
備註
每次網路請求都會提出。WebRequestEvent
它利用該 WebRequestInformation 類別來取得請求資訊。
Note
大多數情況下,你會使用標準 ASP.NET 健康監控類型,並透過設定 healthMonitoring 配置區塊來控制它們的行為。 你也可以建立自訂型別,如下一個範例所示。 如果你建立了自訂事件類型,需要加入自己的資訊,請自訂 FormatCustomEventDetails 方法。 這樣可以避免覆蓋或竄改敏感系統資訊。
建構函式
| 名稱 | Description |
|---|---|
| WebRequestEvent(String, Object, Int32, Int32) |
初始 WebRequestEvent 化類別時會指定事件參數。 |
| WebRequestEvent(String, Object, Int32) |
初始 WebRequestEvent 化類別時會指定事件參數。 |
屬性
| 名稱 | Description |
|---|---|
| EventCode |
取得與事件相關的程式碼值。 (繼承來源 WebBaseEvent) |
| EventDetailCode |
取得事件細節代碼。 (繼承來源 WebBaseEvent) |
| EventID |
取得與事件相關的識別碼。 (繼承來源 WebBaseEvent) |
| EventOccurrence |
會獲得一個代表事件發生次數的計數器。 (繼承來源 WebBaseEvent) |
| EventSequence |
讀取該事件被應用程式提出的次數。 (繼承來源 WebBaseEvent) |
| EventSource |
獲得能引發事件的物件。 (繼承來源 WebBaseEvent) |
| EventTime |
取得事件被提出的時間。 (繼承來源 WebBaseEvent) |
| EventTimeUtc |
取得事件被提出的時間。 (繼承來源 WebBaseEvent) |
| Message |
收到描述事件的訊息。 (繼承來源 WebBaseEvent) |
| ProcessInformation |
取得有關 ASP.NET 應用程式託管流程的資訊。 (繼承來源 WebManagementEvent) |
| RequestInformation |
取得與網頁應用程式請求相關的資訊。 |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| FormatCustomEventDetails(WebEventFormatter) |
提供活動資訊的標準格式。 (繼承來源 WebBaseEvent) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IncrementPerfCounters() |
內部用來增加效能計數器。 |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| Raise() |
透過通知任何已設定的提供者事件已發生,從而提出事件。 (繼承來源 WebBaseEvent) |
| ToString() |
格式化活動資訊以供展示用途。 (繼承來源 WebBaseEvent) |
| ToString(Boolean, Boolean) |
格式化活動資訊以供展示用途。 (繼承來源 WebBaseEvent) |