WebRequestEvent Class
Assembly: System.Web (in system.web.dll)
The WebRequestEvent is raised at every Web request.
It uses the WebRequestInformation class to obtain request information.
Note: |
|---|
| In most cases you will use the standard ASP.NET health-monitoring types and control their behavior by setting the healthMonitoring configuration section. You can also create custom types, as shown in the next example. If you create your custom event type and you need to add your own information, customize the FormatCustomEventDetails method. This will avoid overwriting or tampering with sensitive system information. |
| Topic | Location |
|---|---|
| How to: Implement and Raise Custom ASP.NET Health Monitoring Events | Building ASP .NET Web Applications |
| How to: Implement the Health Monitoring Custom Provider Example | Building ASP .NET Web Applications |
| How to: Implement and Raise Custom ASP.NET Health Monitoring Events | Building ASP .NET Web Applications |
| How to: Implement the Health Monitoring Custom Provider Example | Building ASP .NET Web Applications |
The following code example shows how to derive from the WebRequestEvent class to create a custom event.
Imports System 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 'New ' 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 'New ' 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 'Raise '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 'FormatCustomEventDetails End Class 'SampleWebRequestEvent
The following is an excerpt of the configuration file that enables ASP.NET to use the custom event.
<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>
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
System.Web.Management.WebBaseEvent
System.Web.Management.WebManagementEvent
System.Web.Management.WebRequestEvent
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Note: