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 事件且正在处理该事件。

示例

以下示例演示如何将 枚举与 属性一起使用RequestNotificationCurrentNotification,以确定当前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 中引入。 有关详细信息,请参见版本和依赖关系

适用于

另请参阅