RequestNotification 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指出處理 HttpApplication 要求時,何時發生事件和其他生命週期事件。
此列舉支援其成員值的位元組合。
public enum class RequestNotification
[System.Flags]
public enum RequestNotification
[<System.Flags>]
type RequestNotification =
Public Enum RequestNotification
- 繼承
- 屬性
欄位
| 名稱 | 值 | Description |
|---|---|---|
| BeginRequest | 1 | 表示 BeginRequest 事件已為請求提出並正在處理中。 |
| AuthenticateRequest | 2 | 表示 AuthenticateRequest 事件已為請求提出並正在處理中。 |
| AuthorizeRequest | 4 | 表示 AuthorizeRequest 事件已為請求提出並正在處理中。 |
| ResolveRequestCache | 8 | 表示 ResolveRequestCache 事件已為請求提出並正在處理中。 |
| MapRequestHandler | 16 | 表示 MapRequestHandler 事件已為請求提出並正在處理中。 |
| AcquireRequestState | 32 | 表示 AcquireRequestState 事件已為請求提出並正在處理中。 |
| PreExecuteRequestHandler | 64 | 表示應用程式生命週期中處理請求的處理器被映射之前的一個點。 |
| ExecuteRequestHandler | 128 | 表示映射到請求資源的處理器正被呼叫來處理請求。 |
| ReleaseRequestState | 256 | 表示 ReleaseRequestState 事件已為請求提出並正在處理中。 |
| UpdateRequestCache | 512 | 表示 UpdateRequestCache 事件已為請求提出並正在處理中。 |
| LogRequest | 1024 | 表示 LogRequest 事件已為請求提出並正在處理中。 |
| EndRequest | 2048 | 表示 EndRequest 事件已為請求提出並正在處理中。 |
| SendResponse | 536870912 | 表示請求處理已完成,回應正在傳送中。 |
範例
以下範例說明如何利用 RequestNotification 帶有屬性 CurrentNotification 的枚舉來判斷目前實例中哪個事件 HttpApplication 正在處理請求。
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
備註
RequestNotification列舉結合CurrentNotificationHttpContext類別屬性來判斷目前管線中正在處理的事件。 要判斷該實例中特定事件 HttpApplication 的所有處理程序何時完成處理,請使用該 IsPostNotification 屬性。
此 RequestNotification 型別於 .NET Framework 3.5 中引入。 欲了解更多資訊,請參閱 版本與相依關係。