HttpContext.IsPostNotification 属性

定义

HttpApplication 事件完成处理之后获取 ASP.NET 管道的当前进程点的值。Gets a value that is the current processing point in the ASP.NET pipeline just after an HttpApplication event has finished processing.

public:
 property bool IsPostNotification { bool get(); };
public bool IsPostNotification { get; }
member this.IsPostNotification : bool
Public ReadOnly Property IsPostNotification As Boolean

属性值

如果启用了自定义错误,则为 true;否则,为 falsetrue if custom errors are enabled; otherwise, false.

异常

操作要求 IIS 7.0IIS 7.0 中的集成管道模式并且要求至少为 .NET Framework 3.0。The operation requires the integrated pipeline mode in IIS 7.0IIS 7.0 and at least the .NET Framework 3.0.

示例

下面的示例演示如何使用 IsPostNotification 属性来确定 HttpApplication 对象的事件何时处理完所有关联的事件处理程序。The following example demonstrates how to use the IsPostNotification property to determine when an event of the HttpApplication object has finished processing all the associated event handlers. 此示例中的自定义事件处理程序处理 HttpApplication 对象的多个事件,而 IsPostNotification 属性用于确定在处理特定事件之后调用的代码。The custom event handler in this example handles several events of the HttpApplication object, and the IsPostNotification property is used to determine what code is invoked after a specific event is 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

注解

仅在 IIS 7.0IIS 7.0 的集成模式下支持 IsPostNotification 属性,且至少 .NET Framework 3.0。The IsPostNotification property is only supported with the integrated mode in IIS 7.0IIS 7.0 and at least the .NET Framework 3.0. 如果可用,属性将返回一个布尔值,该值指示 HttpApplication 对象中的事件是否已完成处理。When available, the property returns a Boolean value that indicates whether an event in the HttpApplication object has finished processing.

不应设置 IsPostNotification 属性。The IsPostNotification property is not intended to be set. 相反,它是通过 IIS 7.0IIS 7.0 到每个通知的 ASP.NET 运行时来提供的。Instead, it is provided by IIS 7.0IIS 7.0 to the ASP.NET runtime for each notification. 设置 IsPostNotification 属性将导致编译错误。Setting the IsPostNotification property will result in a compilation error.

在一个事件处理程序处理 HttpApplication 对象的多个事件的情况下,可以结合使用 IsPostNotification 属性和 RequestNotification 枚举,以精确确定当前请求在应用程序生命周期中的位置。In scenarios where multiple events of the HttpApplication object are handled by one event handler, you can use the IsPostNotification property in combination with the RequestNotification enumeration to precisely determine where in the application lifecycle the current request is.

.NET Framework 版本3.5 中引入了 IsPostNotificationIsPostNotification is introduced in the .NET Framework version 3.5. 有关详细信息,请参见版本和依赖关系For more information, see Versions and Dependencies.

适用于

另请参阅