HttpContext.CurrentNotification 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 RequestNotification 值,表示目前正在處理的 HttpApplication 事件。
public:
property System::Web::RequestNotification CurrentNotification { System::Web::RequestNotification get(); };
public System.Web.RequestNotification CurrentNotification { get; }
member this.CurrentNotification : System.Web.RequestNotification
Public ReadOnly Property CurrentNotification As RequestNotification
屬性值
其中一個 RequestNotification 值。
例外狀況
此作業需要 IIS 7.0 中的整合式管線模式,以及至少.NET Framework 3.0 版。
範例
下列範例示範如何使用 CurrentNotification 屬性來判斷正在處理目前要求的物件事件 HttpApplication 。 在此範例中,事件處理常式會處理 物件的數個 HttpApplication 事件,而 CurrentNotification 屬性會決定針對所處理的每個事件叫用的程式碼。
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
備註
屬性 CurrentNotification 需要 IIS 7.0 中的整合式管線模式,以及至少.NET Framework 3.0 版。 當可用時,屬性會傳 RequestNotification 回值。 屬性的值 CurrentNotification 表示實例中的 HttpApplication 哪個事件目前正在處理要求。
屬性 CurrentNotification 不是要設定的。 相反地,IIS 7.0 會在處理 ASP.NET 管線中要求時加以設定。 CurrentNotification設定 屬性會導致編譯錯誤。
CurrentNotification.NET Framework 3.5 版引進。 如需詳細資訊,請參閱版本和相依性。