HttpContext.IsPostNotification HttpContext.IsPostNotification HttpContext.IsPostNotification HttpContext.IsPostNotification Property

定義

取得值,這是在 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整合模式才支援屬性,而且至少.NETFramework3.0。IsPostNotificationThe 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.

不打算設定屬性。 IsPostNotificationThe 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.

IsPostNotification會在 .NET Framework 版本3.5 中引進。IsPostNotification is introduced in the .NET Framework version 3.5. 如需詳細資訊,請參閱版本和相依性For more information, see Versions and Dependencies.

適用於

另請參閱