HttpContext.IsPostNotification Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar ett värde som är den aktuella bearbetningspunkten i den ASP.NET pipelinen strax efter att en HttpApplication händelse har slutfört bearbetningen.
public:
property bool IsPostNotification { bool get(); };
public bool IsPostNotification { get; }
member this.IsPostNotification : bool
Public ReadOnly Property IsPostNotification As Boolean
Egenskapsvärde
trueom anpassade fel är aktiverade. annars . false
Undantag
Åtgärden kräver det integrerade pipelineläget i IIS 7.0 och minst .NET Framework 3.0.
Exempel
I följande exempel visas hur du använder IsPostNotification egenskapen för att avgöra när en händelse av objektet har slutfört bearbetningen av HttpApplication alla associerade händelsehanterare. Den anpassade händelsehanteraren i det här exemplet hanterar flera händelser av HttpApplication objektet och IsPostNotification egenskapen används för att avgöra vilken kod som anropas efter att en viss händelse har hanterats.
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
Kommentarer
Egenskapen IsPostNotification stöds endast med det integrerade läget i IIS 7.0 och åtminstone .NET Framework 3.0. När den är tillgänglig returnerar egenskapen ett booleskt värde som anger om en händelse i objektet har slutfört bearbetningen HttpApplication .
Egenskapen IsPostNotification är inte avsedd att anges. I stället tillhandahålls den av IIS 7.0 till ASP.NET-körningen för varje meddelande. Om du anger egenskapen IsPostNotification resulterar det i ett kompileringsfel.
I scenarier där flera händelser av HttpApplication objektet hanteras av en händelsehanterare kan du använda IsPostNotification egenskapen i kombination med RequestNotification uppräkningen för att exakt avgöra var i programlivscykeln den aktuella begäran finns.
IsPostNotification introduceras i .NET Framework version 3.5. Mer information finns i Versioner och beroenden.