HttpContext.IsPostNotification 屬性

定義

取得值,這是在 HttpApplication 事件完成處理之後 ASP.NET 管線中目前正在處理的點。

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

屬性值

Boolean

如果啟用自訂錯誤,則為 true;否則為 false

例外狀況

此作業需要 IIS 7.0 中的整合式管線模式,以及至少.NET Framework 3.0。

範例

下列範例示範如何使用 IsPostNotification 屬性來判斷物件的事件 HttpApplication 何時完成處理所有相關聯的事件處理常式。 此範例中的自訂事件處理常式會處理物件的數個事件 HttpApplication ,而 IsPostNotification 屬性可用來判斷在特定事件處理之後叫用的程式碼。

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

備註

只有 IsPostNotification IIS 7.0 中的整合模式和至少.NET Framework 3.0 才支援 屬性。 當可用時,屬性會傳回布林值,指出 物件中的 HttpApplication 事件是否已完成處理。

屬性 IsPostNotification 不是要設定的。 而是由 IIS 7.0 提供給每個通知的 ASP.NET 執行時間。 IsPostNotification設定 屬性會導致編譯錯誤。

在物件多個事件 HttpApplication 由一個事件處理常式處理的情況下,您可以使用 IsPostNotification 屬性與 RequestNotification 列舉結合,精確地判斷目前要求在應用程式生命週期中的位置。

IsPostNotification.NET Framework 3.5 版引進。 如需詳細資訊,請參閱版本和相依性

適用於

另請參閱