Condividi tramite


RequestNotification Enumerazione

Definizione

Indica quando si verificano eventi e altri eventi del ciclo di vita durante l'elaborazione di una richiesta di HttpApplication.

Questa enumerazione supporta una combinazione bit per bit dei rispettivi valori dei membri.

public enum class RequestNotification
[System.Flags]
public enum RequestNotification
[<System.Flags>]
type RequestNotification = 
Public Enum RequestNotification
Ereditarietà
RequestNotification
Attributi

Campi

Nome Valore Descrizione
BeginRequest 1

Indica che l'evento è stato generato per la richiesta ed è in corso l'elaborazione BeginRequest .

AuthenticateRequest 2

Indica che l'evento è stato generato per la richiesta ed è in corso l'elaborazione AuthenticateRequest .

AuthorizeRequest 4

Indica che l'evento è stato generato per la richiesta ed è in corso l'elaborazione AuthorizeRequest .

ResolveRequestCache 8

Indica che l'evento è stato generato per la richiesta ed è in corso l'elaborazione ResolveRequestCache .

MapRequestHandler 16

Indica che l'evento è stato generato per la richiesta ed è in corso l'elaborazione MapRequestHandler .

AcquireRequestState 32

Indica che l'evento è stato generato per la richiesta ed è in corso l'elaborazione AcquireRequestState .

PreExecuteRequestHandler 64

Indica un punto nel ciclo di vita dell'applicazione subito prima del mapping del gestore che elabora la richiesta.

ExecuteRequestHandler 128

Indica che il gestore mappato alla risorsa richiesta viene richiamato per elaborare la richiesta.

ReleaseRequestState 256

Indica che l'evento è stato generato per la richiesta ed è in corso l'elaborazione ReleaseRequestState .

UpdateRequestCache 512

Indica che l'evento è stato generato per la richiesta ed è in corso l'elaborazione UpdateRequestCache .

LogRequest 1024

Indica che l'evento è stato generato per la richiesta ed è in corso l'elaborazione LogRequest .

EndRequest 2048

Indica che l'evento è stato generato per la richiesta ed è in corso l'elaborazione EndRequest .

SendResponse 536870912

Indica che l'elaborazione della richiesta è stata completata e che la risposta viene inviata.

Esempio

Nell'esempio seguente viene illustrato come utilizzare l'enumerazione RequestNotification con la CurrentNotification proprietà per determinare quale evento dell'istanza corrente HttpApplication sta elaborando la richiesta.

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

L'enumerazione RequestNotification viene utilizzata con la CurrentNotification proprietà della HttpContext classe per determinare quale evento nella pipeline sta elaborando. Per determinare quando tutti i gestori per un evento specifico dell'istanza hanno terminato l'elaborazione HttpApplication , utilizzare la IsPostNotification proprietà .

Il RequestNotification tipo è stato introdotto in .NET Framework 3.5. Per altre informazioni, vedere Versioni e dipendenze.

Si applica a

Vedi anche