HttpContext.CurrentNotification Proprietà

Definizione

Ottiene un valore RequestNotification che indica l'evento HttpApplication attualmente in elaborazione.Gets a RequestNotification value that indicates the current HttpApplication event that is processing.

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

Valore della proprietà

Uno dei valori di RequestNotification.One of the RequestNotification values.

Eccezioni

L'operazione richiede una modalità pipeline integrata in IIS 7.0IIS 7.0 e .NET Framework versione 3.0 o successiva.The operation requires integrated pipeline mode in IIS 7.0IIS 7.0 and at least the .NET Framework version 3.0.

Esempi

Nell'esempio seguente viene illustrato come utilizzare la proprietà CurrentNotification per determinare quale evento dell'oggetto HttpApplication che gestisce la richiesta corrente è in fase di elaborazione.The following example demonstrates how to use the CurrentNotification property to determine what event of the HttpApplication object that is handling the current request is being processed. Nell'esempio, il gestore eventi gestisce diversi eventi dell'oggetto HttpApplication e la proprietà CurrentNotification determina quale codice viene richiamato per ogni evento gestito.In the example, the event handler handles several events of the HttpApplication object, and the CurrentNotification property determines what code is invoked for each event being handled.

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

Commenti

Per la proprietà CurrentNotification è necessaria la modalità pipeline integrata in IIS 7.0IIS 7.0 e almeno la versione .NET Framework 3,0.The CurrentNotification property requires the integrated pipeline mode in IIS 7.0IIS 7.0 and at least the .NET Framework version 3.0. Se disponibile, la proprietà restituisce un valore RequestNotification.When available, the property returns a RequestNotification value. Il valore della proprietà CurrentNotification indica quale evento nell'istanza HttpApplication sta attualmente elaborando la richiesta.The value of the CurrentNotification property indicates which event in the HttpApplication instance is currently processing the request.

La proprietà CurrentNotification non deve essere impostata.The CurrentNotification property is not intended to be set. Viene invece impostata da IIS 7.0IIS 7.0 durante l'elaborazione della richiesta nella pipeline ASP.NET.Instead, it is set by IIS 7.0IIS 7.0 during the processing of the request in the ASP.NET pipeline. Se si imposta la proprietà CurrentNotification, verrà generato un errore di compilazione.Setting the CurrentNotification property will result in a compilation error.

CurrentNotification è stato introdotto nella versione .NET Framework 3,5.CurrentNotification is introduced in the .NET Framework version 3.5. Per altre informazioni, vedere Versioni e dipendenze.For more information, see Versions and Dependencies.

Si applica a

Vedi anche