WebRequestInformation Klasse

Definition

Stellt Informationen über die aktuelle Webanforderung bereit.

public ref class WebRequestInformation sealed
public sealed class WebRequestInformation
type WebRequestInformation = class
Public NotInheritable Class WebRequestInformation
Vererbung
WebRequestInformation

Beispiele

Im folgenden Codebeispiel wird gezeigt, wie ein benutzerdefiniertes Ereignis implementiert wird, das den WebRequestInformation Typ verwendet.

Außerdem wird ein Auszug aus der Konfigurationsdatei gezeigt, mit der ASP.NET dieses benutzerdefinierte Ereignis verwenden kann.

Stellen Sie sicher, dass Ihr benutzerdefiniertes Ereignis zum richtigen Zeitpunkt ausgelöst wird, d. h. wenn das entsprechende Systemintegritätsereignis ausgelöst wird, das ersetzt wird.

<healthMonitoring  
  heartBeatInterval="0" enabled="true">  

  <profiles>  
    <add name="Custom"   
      minInstances="1"   
      maxLimit="Infinite"   
      minInterval="00:00:00" />  
  </profiles>  

  <eventMappings>  

    <add   
      name="SampleWebRequestInformation"   
      type="SamplesAspNet.SampleWebRequestInformation,webrequestinformation,Version=1.0.1782.28745, Culture=neutral, PublicKeyToken=79955d9b8521c250,processorArchitecture=MSIL" />  

  </eventMappings>  

  <rules>  

    <add name="Custom Web Request Info Event"   
      eventName="SampleWebRequestInformation"   
      provider="EventLogProvider"  
      profile="Custom" />  

  </rules>  

</healthMonitoring>  

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 that uses
    // WebRequestInformation. 
    public class SampleWebRequestInformation :
        WebRequestEvent
    {
        private StringBuilder eventInfo;

        // Instantiate events identified 
        // only by their event code.
        public SampleWebRequestInformation(string msg,
            object eventSource, int eventCode):
        base(msg, eventSource, eventCode)
        {
            // Perform custom initialization.
            eventInfo = new StringBuilder();
            eventInfo.Append(string.Format(
                "Event created at: {0}",
                EventTime.ToString()));
        }

        // Instantiate events identified by 
        // their event code.and related 
        // event detailed code.
        public SampleWebRequestInformation(string msg,
            object eventSource, int eventCode,
            int eventDetailCode)
            :
            base(msg, eventSource,
            eventCode, eventDetailCode)
        {
            // Perform custom initialization.
            eventInfo = new StringBuilder();
            eventInfo.Append(string.Format(
                "Event created at: {0}",
                EventTime.ToString()));
        }


        // Raises the event.
        public override void Raise()
        {
            // Perform custom processing. 
            eventInfo.Append(string.Format(
                "Event raised at: {0}",
               EventTime.ToString()));
            // Raise the event.
            base.Raise();
        }

        // Get the request path.
        public string GetRequestPath()
        {
            // Get the request path.
            return (string.Format(
                "Request path: {0}",
                RequestInformation.RequestPath));
        }

        // Get the request URL.
        public string GetRequestUrl()
        {
            // Get the request URL.
            return (string.Format(
                "Request URL: {0}",
                RequestInformation.RequestUrl));
        }

        // Get the request user host address.
        public string GetRequestUserHostAdddress()
        {
            // Get the request user host address.
            return (string.Format(
                "Request user host address: {0}",
                RequestInformation.UserHostAddress));
        }

        // Get the request principal.
        public string GetRequestPrincipal()
        {
            // Get the request principal.
            return (string.Format(
                "Request principal name: {0}",
                RequestInformation.Principal.Identity.Name));
        }


        // Formats Web request event information.
        public override void FormatCustomEventDetails(
         WebEventFormatter formatter)
        {

            // Add custom data.

            formatter.AppendLine("");
            formatter.AppendLine(
                "Custom Request Information:");

            formatter.IndentationLevel += 1;

            // Display the request information obtained 
            // using the WebRequestInformation object.
            formatter.AppendLine(GetRequestPath());
            formatter.AppendLine(GetRequestUrl());
            formatter.AppendLine(GetRequestUserHostAdddress());
            formatter.AppendLine(GetRequestPrincipal());

            formatter.IndentationLevel -= 1;

            formatter.AppendLine(eventInfo.ToString());
        }

    }
}
Imports System.Text
Imports System.Web
Imports System.Web.Management
Imports System.Web.UI
Imports System.Web.UI.WebControls


' Implements a custom WebRequestEvent that uses
' WebRequestInformation. 

Public Class SampleWebRequestInformation
   Inherits WebRequestEvent
   Private eventInfo As StringBuilder
   
   
   ' Instantiate 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.
        eventInfo = New StringBuilder()
        eventInfo.Append(String.Format( _
        "Event created at: {0}", EventTime.ToString()))
    End Sub
   
   
   ' Instantiate 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.
        eventInfo = New StringBuilder()
        eventInfo.Append(String.Format( _
        "Event created at: {0}", EventTime.ToString()))
    End Sub
   
   
   ' Raises the event.
   Public Overrides Sub Raise()
      ' Perform custom processing. 
        eventInfo.Append(String.Format( _
        "Event raised at: {0}", EventTime.ToString()))
      ' Raise the event.
      MyBase.Raise()
   End Sub
   
   ' Get the request path.
   Public Function GetRequestPath() As String
      ' Get the request path.
        Return String.Format( _
        "Request path: {0}", RequestInformation.RequestPath)
   End Function 'GetRequestPath
   
   ' Get the request URL.
   Public Function GetRequestUrl() As String
      ' Get the request URL.
        Return String.Format("Request URL: {0}", _
        RequestInformation.RequestUrl)
   End Function 'GetRequestUrl
   
   ' Get the request user host address.
   Public Function GetRequestUserHostAdddress() As String
      ' Get the request user host address.
        Return String.Format( _
        "Request user host address: {0}", _
        RequestInformation.UserHostAddress)
   End Function 'GetRequestUserHostAdddress
   
   ' Get the request principal.
   Public Function GetRequestPrincipal() As String
      ' Get the request principal.
        Return String.Format( _
        "Request principal name: {0}", _
        RequestInformation.Principal.Identity.Name)
   End Function 'GetRequestPrincipal
   
   ' Formats Web request event information.
    Public Overrides Sub FormatCustomEventDetails( _
    ByVal formatter As WebEventFormatter)

        ' Add custom data.
        formatter.AppendLine("")
        formatter.AppendLine("Custom Request Information:")

        formatter.IndentationLevel += 1

        ' Display the request information obtained 
        ' using the WebRequestInformation object.
        formatter.AppendLine(GetRequestPath())
        formatter.AppendLine(GetRequestUrl())
        formatter.AppendLine(GetRequestUserHostAdddress())
        formatter.AppendLine(GetRequestPrincipal())
        formatter.IndentationLevel -= 1

        formatter.AppendLine(eventInfo.ToString())
    End Sub

End Class

Hinweise

mit ASP.NET Integritätsüberwachung können Mitarbeiter von Produktion und Betrieb bereitgestellte Webanwendungen verwalten. Der System.Web.Management Namespace enthält die Integritätsereignistypen, die für das Packen von Integritätsstatusdaten der Anwendung verantwortlich sind, und die Anbietertypen, die für die Verarbeitung dieser Daten verantwortlich sind. Es enthält auch unterstützende Typen, die bei der Verwaltung von Integritätsereignissen helfen.

Instanzen der WebRequestInformation -Klasse enthalten Informationen, die mit den WebRequestEventTypen , WebAuditEvent, WebErrorEventoder WebRequestErrorEvent abgerufen werden.

Ihre Anwendung benötigt die entsprechenden Berechtigungen für den Zugriff auf geschützte Informationen, die von diesem Typ bereitgestellt werden.

Hinweis

In den meisten Fällen können Sie die ASP.NET Typen der Integritätsüberwachung wie implementiert verwenden, und Sie steuern das System zur Integritätsüberwachung, indem Sie Werte im healthMonitoring Konfigurationsabschnitt angeben. Sie können auch von den Integritätsüberwachungstypen ableiten, um eigene benutzerdefinierte Ereignisse und Anbieter zu erstellen. Ein Beispiel zum Erstellen einer benutzerdefinierten Ereignisklasse finden Sie im Beispiel in diesem Thema.

Eigenschaften

Principal

Ruft die Instanz des der Webanforderung zugeordneten Prinzipals für verwalteten Code ab.

RequestPath

Ruft den physikalischen Pfad der Webanforderung ab.

RequestUrl

Ruft den logischen Pfad der Anforderung ab.

ThreadAccountName

Ruft eine Zeichenfolge ab, die den Windows-Anmeldenamen des Benutzers darstellt, für den der Code ausgeführt wird.

UserHostAddress

Ruft die Benutzerhostadresse ab.

Methoden

Equals(Object)

Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist.

(Geerbt von Object)
FormatToString(WebEventFormatter)

Formatiert die Webanforderungsinformationen.

GetHashCode()

Fungiert als Standardhashfunktion.

(Geerbt von Object)
GetType()

Ruft den Type der aktuellen Instanz ab.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)

Gilt für:

Weitere Informationen