Freigeben über


HttpContext.CurrentNotification Eigenschaft

Definition

Ruft einen RequestNotification Wert ab, der das aktuelle HttpApplication Ereignis angibt, das verarbeitet wird.

public:
 property System::Web::RequestNotification CurrentNotification { System::Web::RequestNotification get(); };
public System.Web.RequestNotification CurrentNotification { get; }
member this.CurrentNotification : System.Web.RequestNotification
Public ReadOnly Property CurrentNotification As RequestNotification

Eigenschaftswert

Einer der RequestNotification Werte.

Ausnahmen

Für den Vorgang ist der integrierte Pipelinemodus in IIS 7.0 und mindestens die .NET Framework-Version 3.0 erforderlich.

Beispiele

Im folgenden Beispiel wird veranschaulicht, wie die CurrentNotification Eigenschaft verwendet wird, um zu bestimmen, welches Ereignis des HttpApplication Objekts, das die aktuelle Anforderung verarbeitet, verarbeitet wird. Im Beispiel behandelt der Ereignishandler mehrere Ereignisse des HttpApplication Objekts, und die CurrentNotification Eigenschaft bestimmt, welcher Code für jedes behandelte Ereignis aufgerufen wird.

using System;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;

// Module that demonstrates one event handler for several events.
namespace Samples
{
    public class ModuleExampleTestCS : IHttpModule
    {
        public ModuleExampleTestCS()
        {
            // Constructor
        }
        public void Init(HttpApplication app)
        {
            app.AuthenticateRequest += new EventHandler(App_Handler);
            app.PostAuthenticateRequest += new EventHandler(App_Handler);
            app.LogRequest += new EventHandler(App_Handler);
            app.PostLogRequest += new EventHandler(App_Handler);
        }
        public void Dispose()
        {
        }
        // One handler for AuthenticationRequest, PostAuthenticateRequest,
    // LogRequest, and PostLogRequest events
        public void App_Handler(object source, EventArgs e)
        {
            HttpApplication app = (HttpApplication)source;
            HttpContext context = app.Context;

            if (context.CurrentNotification == RequestNotification.AuthenticateRequest)
            {

                if (!context.IsPostNotification)
                {
                    // Put code here that is invoked when the AuthenticateRequest event is raised.
                }
                else
                {
                    // PostAuthenticateRequest 
                    // Put code here that runs after the AuthenticateRequest event completes.
                }
            }
            if (context.CurrentNotification == RequestNotification.LogRequest)
            {
                if (!context.IsPostNotification)
                {
                    // Put code here that is invoked when the LogRequest event is raised.
                }
                else
                {
                    // PostLogRequest
                    // Put code here that runs after the LogRequest event completes.
                }
            }
        }
    }
}
Imports System.Data
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI

' Module that demonstrates one event handler for several events.
Namespace Samples

    Public Class ModuleExampleTestVB
        Implements IHttpModule

        Public Sub New()
            ' Constructor
        End Sub

        Public Sub Init(ByVal app As HttpApplication) Implements IHttpModule.Init
            AddHandler app.AuthenticateRequest, AddressOf Me.App_Handler
            AddHandler app.PostAuthenticateRequest, AddressOf Me.App_Handler
            AddHandler app.LogRequest, AddressOf Me.App_Handler
            AddHandler app.PostLogRequest, AddressOf Me.App_Handler
        End Sub

        Public Sub Dispose() Implements IHttpModule.Dispose
        End Sub

        ' One handler for AuthenticationRequest, PostAuthenticateRequest,
    ' LogRequest, and PostLogRequest events
        Public Sub App_Handler(ByVal source As Object, ByVal e As EventArgs)
            Dim app As HttpApplication = CType(source, HttpApplication)
            Dim context As HttpContext = app.Context

            If (context.CurrentNotification = RequestNotification.AuthenticateRequest) Then

                If Not (context.IsPostNotification) Then

                    ' Put code here that is invoked when the AuthenticateRequest event is raised.
                Else

                    ' PostAuthenticateRequest 
                    ' Put code here that runs after the AuthenticateRequest event completes.

                End If
            End If

            If (context.CurrentNotification = RequestNotification.LogRequest) Then

                If Not (context.IsPostNotification) Then

                    ' Put code here that is invoked when the LogRequest event is raised.

                Else
                    ' PostLogRequest
                    ' Put code here that runs after the LogRequest event completes.

                End If
            End If
        End Sub
    End Class

End Namespace

Hinweise

Für die CurrentNotification Eigenschaft ist der integrierte Pipelinemodus in IIS 7.0 und mindestens die .NET Framework-Version 3.0 erforderlich. Wenn verfügbar, gibt die Eigenschaft einen RequestNotification Wert zurück. Der Wert der CurrentNotification Eigenschaft gibt an, welches Ereignis in der HttpApplication Instanz derzeit die Anforderung verarbeitet.

Die CurrentNotification Eigenschaft soll nicht festgelegt werden. Stattdessen wird sie von IIS 7.0 während der Verarbeitung der Anforderung in der ASP.NET Pipeline festgelegt. Das Festlegen der CurrentNotification Eigenschaft führt zu einem Kompilierungsfehler.

CurrentNotification wird in .NET Framework, Version 3.5, eingeführt. Weitere Informationen finden Sie unter "Versionen und Abhängigkeiten".

Gilt für:

Weitere Informationen