RequestNotification 列舉

定義

表示正在處理 HttpApplication 要求時,事件和其他生命週期事件發生的時機。

此列舉支援其成員值的位元組合。

public enum class RequestNotification
[System.Flags]
public enum RequestNotification
[<System.Flags>]
type RequestNotification = 
Public Enum RequestNotification
繼承
RequestNotification
屬性

欄位

AcquireRequestState 32

表示 AcquireRequestState 事件已針對要求引發且正在處理中。

AuthenticateRequest 2

表示 AuthenticateRequest 事件已針對要求引發且正在處理中。

AuthorizeRequest 4

表示 AuthorizeRequest 事件已針對要求引發且正在處理中。

BeginRequest 1

表示 BeginRequest 事件已針對要求引發且正在處理中。

EndRequest 2048

表示 EndRequest 事件已針對要求引發且正在處理中。

ExecuteRequestHandler 128

表示正在叫用對應至所要求資源的處理常式,以處理要求。

LogRequest 1024

表示 LogRequest 事件已針對要求引發且正在處理中。

MapRequestHandler 16

表示 MapRequestHandler 事件已針對要求引發且正在處理中。

PreExecuteRequestHandler 64

表示應用程式生命週期中,在已對應會處理要求的處理常式之前的點。

ReleaseRequestState 256

表示 ReleaseRequestState 事件已針對要求引發且正在處理中。

ResolveRequestCache 8

表示 ResolveRequestCache 事件已針對要求引發且正在處理中。

SendResponse 536870912

表示已完成要求處理,且正在傳送回應。

UpdateRequestCache 512

表示 UpdateRequestCache 事件已針對要求引發且正在處理中。

範例

下列範例示範如何搭配 CurrentNotification 屬性使用 RequestNotification 列舉,以判斷目前 HttpApplication 實例的哪個事件正在處理要求。

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

備註

列舉 RequestNotification 會與 類別的 HttpContext 屬性搭配 CurrentNotification 使用,以判斷管線中目前正在處理的事件。 若要判斷實例特定事件 HttpApplication 的所有處理常式何時都已完成處理,請使用 IsPostNotification 屬性。

RequestNotification 類型會在 .NET Framework 3.5 中引進。 如需詳細資訊,請參閱版本和相依性

適用於

另請參閱