Defines the methods, properties, and events that are common to all application objects in an ASP.NET application. This class is the base class for applications that are defined by the user in the Global.asax file.
Assembly: System.Web (in System.Web.dll)
'Declaration <AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ Public Class HttpApplication _ Implements IHttpAsyncHandler, IHttpHandler, IComponent, IDisposable 'Usage Dim instance As HttpApplication
Instances of the class are created in the ASP.NET infrastructure, not by the user directly. One instance of the class is used to process many requests in its lifetime. However, it can process only one request at a time. Thus, member variables can be used to store per-request data.
An application raises events that can be handled by custom modules that implement the IHttpModule interface or by event handler code that is defined in the Global.asax file. Custom modules that implement the IHttpModule interface can be put in the App_Code folder or in a DLL in the Bin folder.
When running IIS 7.0 in Integrated mode, custom modules in the App_Code folder or Bin folder apply to all requests in the request pipeline. Event handler code in the Global.asax file only applies to requests that are mapped to an ASP.NET handler.
The application events are raised in the following order:
After the PostResolveRequestCache event and before the PostMapRequestHandler event, an event handler (which is a page that corresponds to the request URL) is created. When a server is running IIS 7.0 in Integrated mode and at least the .NET Framework version 3.0, the MapRequestHandler event is raised. When a server is running IIS 7.0 in Classic mode or an earlier version of IIS, this event cannot be handled.
The event handler is executed.
After the PostReleaseRequestState event is raised, any existing response filters will filter the output.
This event is supported in IIS 7.0 Integrated mode and at least the .NET Framework 3.0
This event is supported IIS 7.0 Integrated mode and at least the .NET Framework 3.0
The following two examples demonstrate how to use the class and its events. The first example demonstrates how to create a custom HTTP module and connect an event to it. The second example demonstrates how to modify the Web.config file.
The following example demonstrates how to create a custom HTTP module and connect the AcquireRequestState event to the HTTP module. HTTP modules intercept each request to Web application resources, thereby allowing you to filter client requests. Any HTTP module that subscribes to an event must implement the IHttpModule interface.
Imports System Imports System.Web Namespace Samples.AspNet.VB Public Class CustomHTTPModule Implements IHttpModule Public Sub New() ' Class constructor. End Sub ' Classes that inherit IHttpModule ' must implement the Init and Dispose methods. Public Sub Init(ByVal app As HttpApplication) Implements IHttpModule.Init AddHandler app.AcquireRequestState, AddressOf app_AcquireRequestState AddHandler app.PostAcquireRequestState, AddressOf app_PostAcquireRequestState End Sub Public Sub Dispose() Implements IHttpModule.Dispose ' Add code to clean up the ' instance variables of a module. End Sub ' Define a custom AcquireRequestState event handler. Public Sub app_AcquireRequestState(ByVal o As Object, ByVal ea As EventArgs) Dim httpApp As HttpApplication = CType(o, HttpApplication) Dim ctx As HttpContext = HttpContext.Current ctx.Response.Write(" Executing AcquireRequestState ") End Sub ' Define a custom PostAcquireRequestState event handler. Public Sub app_PostAcquireRequestState(ByVal o As Object, ByVal ea As EventArgs) Dim httpApp As HttpApplication = CType(o, HttpApplication) Dim ctx As HttpContext = HttpContext.Current ctx.Response.Write(" Executing PostAcquireRequestState ") End Sub End Class End Namespace
Before an event in a custom HTTP module can occur, you must modify the configuration settings in the Web.config file to notify ASP.NET about the HTTP module. The following example shows the appropriate configuration setting in the httpModules section of the Web.config file. The following setting applies to IIS 7.0 Classic mode and to earlier versions of IIS.
<configuration> <system.web> <httpModules> <add type="Samples.AspNet.VB.CustomHTTPModule" name="CustomHttpModule" /> </httpModules> </system.web> </configuration>
The following setting applies to IIS 7.0 Integrated mode.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.