WebThreadInformation Klasse

Definition

Stellt Informationen über den Zustand eines Threads in einem ASP.NET-Prozess bereit.

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

Beispiele

Das folgende Codebeispiel umfasst zwei Teile. Der erste ist ein Auszug aus einer Konfigurationsdatei, die es ASP.NET ermöglicht, ein benutzerdefiniertes Ereignis zu verwenden, das den WebThreadInformation Typ verwendet. Der zweite zeigt, wie das benutzerdefinierte Ereignis implementiert wird, das den WebThreadInformation Typ verwendet.

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="SampleWebThreadInformation"   
type="SamplesAspNet.SampleWebThreadInformation,webthreadinformation, Version=1.0.1782.29648, Culture=neutral, PublicKeyToken=b3283a2de7dd3f27, processorArchitecture=MSIL" />  

  </eventMappings>  

  <rules>  

    <add name="Custom Web Thread Info Event"   
      eventName="SampleWebThreadInformation"   
      provider="EventLogProvider"  
      profile="Custom" />  

  </rules>  

</healthMonitoring>  

using System;
using System.Text;
using System.Web;
using System.Web.Management;

namespace SamplesAspNet
{
    // Implements a custom WebErrorstEvent that uses the 
    // WebThreadInformation. 
    public class SampleWebThreadInformation :
        WebErrorEvent
    {
        private StringBuilder eventInfo;

        // Instantiate events identified 
        // only by their event code.
        public SampleWebThreadInformation(
            string msg, object eventSource,
            int eventCode, Exception e)
            :
            base(msg, eventSource, eventCode, e)
        {
            // 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 impersonation mode.
        public string GetThreadImpersonation()
        {
            return (string.Format(
                "Is impersonating: {0}",
                ThreadInformation.IsImpersonating.ToString()));
        }

        // Get the stack trace.
        public string GetThreadStackTrace()
        {
            return (string.Format(
                "Stack trace: {0}",
                ThreadInformation.StackTrace));
        }

        // Get the account name.
        public string GetThreadAccountName()
        {
            return (string.Format(
                "Request user host address: {0}",
                ThreadInformation.ThreadAccountName));
        }

        // Get the task Id.
        public string GetThreadId()
        {
            // Get the request principal.
            return (string.Format(
                "Thread Id: {0}",
                ThreadInformation.ThreadID.ToString()));
        }


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

            // Add custom data.

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

            formatter.IndentationLevel += 1;

            // Display the thread information obtained 
            formatter.AppendLine(GetThreadImpersonation());
            formatter.AppendLine(GetThreadStackTrace());
            formatter.AppendLine(GetThreadAccountName());
            formatter.AppendLine(GetThreadId());
            formatter.IndentationLevel -= 1;

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

    }
}
Imports System.Text
Imports System.Web
Imports System.Web.Management



' Implements a custom WebErrorstEvent that uses the 
' WebThreadInformation. 

Public Class SampleWebThreadInformation
   Inherits WebErrorEvent
   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, ByVal e As Exception)
        MyBase.New(msg, eventSource, eventCode, e)
        ' 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 impersonation mode.
   Public Function GetThreadImpersonation() As String
        Return String.Format( _
        "Is impersonating: {0}", _
        ThreadInformation.IsImpersonating.ToString())
   End Function 'GetThreadImpersonation
   
   ' Get the stack trace.
   Public Function GetThreadStackTrace() As String
        Return String.Format( _
        "Stack trace: {0}", _
        ThreadInformation.StackTrace)
   End Function 'GetThreadStackTrace
   
   ' Get the account name.
   Public Function GetThreadAccountName() As String
        Return String.Format( _
        "Request user host address: {0}", _
        ThreadInformation.ThreadAccountName)
   End Function 'GetThreadAccountName
   
   ' Get the task Id.
   Public Function GetThreadId() As String
      ' Get the request principal.
        Return String.Format( _
        "Thread Id: {0}", _
        ThreadInformation.ThreadID.ToString())
   End Function 'GetThreadId
   
   ' Formats Web request event information.
    Public Overrides Sub FormatCustomEventDetails( _
    ByVal formatter As WebEventFormatter)

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

        formatter.IndentationLevel += 1

        ' Display the thread information obtained 
        formatter.AppendLine(GetThreadImpersonation())
        formatter.AppendLine(GetThreadStackTrace())
        formatter.AppendLine(GetThreadAccountName())
        formatter.AppendLine(GetThreadId())
        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 WebThreadInformation -Klasse enthalten Informationen, die entweder mithilfe des WebErrorEvent Typs oder des Typs 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

IsImpersonating

Ruft den aktuellen Threadidentitätswechselmodus ab.

StackTrace

Ruft die aktuelle im Thread verwaltete Stapelüberwachung ab.

ThreadAccountName

Ruft den Threadkontonamen ab.

ThreadID

Ruft den aktuellen Threadbezeichner ab.

Methoden

Equals(Object)

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

(Geerbt von Object)
FormatToString(WebEventFormatter)

Formatiert Threadinformationen.

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