語言

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

屬性值

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 版本中引入。 欲了解更多資訊,請參閱 版本與相依關係。

適用於

另請參閱