HttpApplication Class
TOC
Collapse the table of content
Expand the table of content

HttpApplication Class

 

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.

Namespace:   System.Web
Assembly:  System.Web (in System.Web.dll)

System.Object
  System.Web.HttpApplication

public class HttpApplication : IComponent, IDisposable, IHttpAsyncHandler, 
	IHttpHandler

NameDescription
System_CAPS_pubmethodHttpApplication()

Initializes a new instance of the HttpApplication class.

NameDescription
System_CAPS_pubpropertyApplication

Gets the current state of an application.

System_CAPS_pubpropertyContext

Gets HTTP-specific information about the current request.

System_CAPS_protpropertyEvents

Gets the list of event handler delegates that process all application events.

System_CAPS_pubpropertyModules

Gets the collection of modules for the current application.

System_CAPS_pubpropertyRequest

Gets the intrinsic request object for the current request.

System_CAPS_pubpropertyResponse

Gets the intrinsic response object for the current request.

System_CAPS_pubpropertyServer

Gets the intrinsic server object for the current request.

System_CAPS_pubpropertySession

Gets the intrinsic session object that provides access to session data.

System_CAPS_pubpropertySite

Gets or sets a site interface for an IComponent implementation.

System_CAPS_pubpropertyUser

Gets the intrinsic user object for the current request.

NameDescription
System_CAPS_pubmethodAddOnAcquireRequestStateAsync(BeginEventHandler, EndEventHandler)

Adds the specified AcquireRequestState event to the collection of asynchronous AcquireRequestState event handlers for the current request.

System_CAPS_pubmethodAddOnAcquireRequestStateAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified AcquireRequestState event to the collection of asynchronous AcquireRequestState event handlers for the current request.

System_CAPS_pubmethodAddOnAuthenticateRequestAsync(BeginEventHandler, EndEventHandler)

Adds the specified AuthenticateRequest event to the collection of asynchronous AuthenticateRequest event handlers for the current request.

System_CAPS_pubmethodAddOnAuthenticateRequestAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified AuthenticateRequest event to the collection of asynchronous AuthenticateRequest event handlers for the current request.

System_CAPS_pubmethodAddOnAuthorizeRequestAsync(BeginEventHandler, EndEventHandler)

Adds the specified AuthorizeRequest event to the collection of asynchronous AuthorizeRequest event handlers for the current request.

System_CAPS_pubmethodAddOnAuthorizeRequestAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified AuthorizeRequest event to the collection of asynchronous AuthorizeRequest event handlers for the current request.

System_CAPS_pubmethodAddOnBeginRequestAsync(BeginEventHandler, EndEventHandler)

Adds the specified BeginRequest event to the collection of asynchronous BeginRequest event handlers for the current request.

System_CAPS_pubmethodAddOnBeginRequestAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified BeginRequest event to the collection of asynchronous BeginRequest event handlers for the current request.

System_CAPS_pubmethodAddOnEndRequestAsync(BeginEventHandler, EndEventHandler)

Adds the specified EndRequest event to the collection of asynchronous EndRequest event handlers for the current request.

System_CAPS_pubmethodAddOnEndRequestAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified EndRequest event to the collection of asynchronous EndRequest event handlers for the current request.

System_CAPS_pubmethodAddOnLogRequestAsync(BeginEventHandler, EndEventHandler)

Adds the specified LogRequest event to the collection of asynchronous LogRequest event handlers for the current request.

System_CAPS_pubmethodAddOnLogRequestAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified LogRequest event to the collection of asynchronous LogRequest event handlers for the current request.

System_CAPS_pubmethodAddOnMapRequestHandlerAsync(BeginEventHandler, EndEventHandler)

Adds the specified MapRequestHandler event to the collection of asynchronous MapRequestHandler event handlers for the current request.

System_CAPS_pubmethodAddOnMapRequestHandlerAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified MapRequestHandler event to the collection of asynchronous MapRequestHandler event handlers for the current request.

System_CAPS_pubmethodAddOnPostAcquireRequestStateAsync(BeginEventHandler, EndEventHandler)

Adds the specified PostAcquireRequestState event to the collection of asynchronous PostAcquireRequestState event handlers for the current request.

System_CAPS_pubmethodAddOnPostAcquireRequestStateAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified PostAcquireRequestState event to the collection of asynchronous PostAcquireRequestState event handlers for the current request.

System_CAPS_pubmethodAddOnPostAuthenticateRequestAsync(BeginEventHandler, EndEventHandler)

Adds the specified PostAuthenticateRequest event to the collection of asynchronous PostAuthenticateRequest event handlers for the current request.

System_CAPS_pubmethodAddOnPostAuthenticateRequestAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified PostAuthorizeRequest event to the collection of asynchronous PostAuthorizeRequest event handlers for the current request.

System_CAPS_pubmethodAddOnPostAuthorizeRequestAsync(BeginEventHandler, EndEventHandler)

Adds the specified PostAuthorizeRequest event to the collection of asynchronous PostAuthorizeRequest event handlers for the current request.

System_CAPS_pubmethodAddOnPostAuthorizeRequestAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified PostAuthorizeRequest to the collection of asynchronous PostAuthorizeRequest event handlers for the current request.

System_CAPS_pubmethodAddOnPostLogRequestAsync(BeginEventHandler, EndEventHandler)

Adds the specified PostLogRequest event to the collection of asynchronous PostLogRequest event handlers for the current request.

System_CAPS_pubmethodAddOnPostLogRequestAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified PostLogRequest event to the collection of asynchronous PostLogRequest event handlers for the current request.

System_CAPS_pubmethodAddOnPostMapRequestHandlerAsync(BeginEventHandler, EndEventHandler)

Adds the specified PostMapRequestHandler event to the collection of asynchronous PostMapRequestHandler event handlers for the current request.

System_CAPS_pubmethodAddOnPostMapRequestHandlerAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified PostMapRequestHandler event to the collection of asynchronous PostMapRequestHandler event handlers for the current request.

System_CAPS_pubmethodAddOnPostReleaseRequestStateAsync(BeginEventHandler, EndEventHandler)

Adds the specified PostReleaseRequestState event to the collection of asynchronous PostReleaseRequestState event handlers for the current request.

System_CAPS_pubmethodAddOnPostReleaseRequestStateAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified PostReleaseRequestState event to the collection of asynchronous PostReleaseRequestState event handlers for the current request.

System_CAPS_pubmethodAddOnPostRequestHandlerExecuteAsync(BeginEventHandler, EndEventHandler)

Adds the specified PostRequestHandlerExecute event to the collection of asynchronous PostRequestHandlerExecute event handlers for the current request.

System_CAPS_pubmethodAddOnPostRequestHandlerExecuteAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified PostRequestHandlerExecute event to the collection of asynchronous PostRequestHandlerExecute event handlers for the current request.

System_CAPS_pubmethodAddOnPostResolveRequestCacheAsync(BeginEventHandler, EndEventHandler)

Adds the specified PostResolveRequestCache event to the collection of asynchronous PostResolveRequestCache event handlers for the current request.

System_CAPS_pubmethodAddOnPostResolveRequestCacheAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified PostResolveRequestCache event to the collection of asynchronous PostResolveRequestCache event handlers for the current request.

System_CAPS_pubmethodAddOnPostUpdateRequestCacheAsync(BeginEventHandler, EndEventHandler)

Adds the specified PostUpdateRequestCache event to the collection of asynchronous PostUpdateRequestCache event handlers for the current request.

System_CAPS_pubmethodAddOnPostUpdateRequestCacheAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified PostUpdateRequestCache event to the collection of asynchronous PostUpdateRequestCache event handlers for the current request.

System_CAPS_pubmethodAddOnPreRequestHandlerExecuteAsync(BeginEventHandler, EndEventHandler)

Adds the specified PreRequestHandlerExecute event to the collection of asynchronous PreRequestHandlerExecute event handlers for the current request.

System_CAPS_pubmethodAddOnPreRequestHandlerExecuteAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified PreRequestHandlerExecute event to the collection of asynchronous PreRequestHandlerExecute event handlers for the current request.

System_CAPS_pubmethodAddOnReleaseRequestStateAsync(BeginEventHandler, EndEventHandler)

Adds the specified ReleaseRequestState event to the collection of asynchronous ReleaseRequestState event handlers for the current request.

System_CAPS_pubmethodAddOnReleaseRequestStateAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified ReleaseRequestState event to the collection of asynchronous ReleaseRequestState event handlers for the current request.

System_CAPS_pubmethodAddOnResolveRequestCacheAsync(BeginEventHandler, EndEventHandler)

Adds the specified ResolveRequestCache event handler to the collection of asynchronous ResolveRequestCache event handlers for the current request.

System_CAPS_pubmethodAddOnResolveRequestCacheAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified ResolveRequestCache event handler to the collection of asynchronous ResolveRequestCache event handlers for the current request.

System_CAPS_pubmethodAddOnUpdateRequestCacheAsync(BeginEventHandler, EndEventHandler)

Adds the specified UpdateRequestCache event to the collection of asynchronous UpdateRequestCache event handlers for the current request.

System_CAPS_pubmethodAddOnUpdateRequestCacheAsync(BeginEventHandler, EndEventHandler, Object)

Adds the specified UpdateRequestCache event to the collection of asynchronous UpdateRequestCache event handlers for the current request.

System_CAPS_pubmethodCompleteRequest()

Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event.

System_CAPS_pubmethodDispose()

Disposes the HttpApplication instance.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetOutputCacheProviderName(HttpContext)

Gets the name of the default output-cache provider that is configured for a Web site.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodGetVaryByCustomString(HttpContext, String)

Provides an application-wide implementation of the VaryByCustom property.

System_CAPS_pubmethodInit()

Executes custom initialization code after all event handler modules have been added.

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_staticRegisterModule(Type)

Registers an application module.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubeventAcquireRequestState

Occurs when ASP.NET acquires the current state (for example, session state) that is associated with the current request.

System_CAPS_pubeventAuthenticateRequest

Occurs when a security module has established the identity of the user.

System_CAPS_pubeventAuthorizeRequest

Occurs when a security module has verified user authorization.

System_CAPS_pubeventBeginRequest

Occurs as the first event in the HTTP pipeline chain of execution when ASP.NET responds to a request.

System_CAPS_pubeventDisposed

Occurs when the application is disposed.

System_CAPS_pubeventEndRequest

Occurs as the last event in the HTTP pipeline chain of execution when ASP.NET responds to a request.

System_CAPS_pubeventError

Occurs when an unhandled exception is thrown.

System_CAPS_pubeventLogRequest

Occurs just before ASP.NET performs any logging for the current request.

System_CAPS_pubeventMapRequestHandler

This API supports the product infrastructure and is not intended to be used directly from your code. Occurs when the handler is selected to respond to the request.

System_CAPS_pubeventPostAcquireRequestState

Occurs when the request state (for example, session state) that is associated with the current request has been obtained.

System_CAPS_pubeventPostAuthenticateRequest

Occurs when a security module has established the identity of the user.

System_CAPS_pubeventPostAuthorizeRequest

Occurs when the user for the current request has been authorized.

System_CAPS_pubeventPostLogRequest

Occurs when ASP.NET has completed processing all the event handlers for the LogRequest event.

System_CAPS_pubeventPostMapRequestHandler

Occurs when ASP.NET has mapped the current request to the appropriate event handler.

System_CAPS_pubeventPostReleaseRequestState

Occurs when ASP.NET has completed executing all request event handlers and the request state data has been stored.

System_CAPS_pubeventPostRequestHandlerExecute

Occurs when the ASP.NET event handler (for example, a page or an XML Web service) finishes execution.

System_CAPS_pubeventPostResolveRequestCache

Occurs when ASP.NET bypasses execution of the current event handler and allows a caching module to serve a request from the cache.

System_CAPS_pubeventPostUpdateRequestCache

Occurs when ASP.NET finishes updating caching modules and storing responses that are used to serve subsequent requests from the cache.

System_CAPS_pubeventPreRequestHandlerExecute

Occurs just before ASP.NET starts executing an event handler (for example, a page or an XML Web service).

System_CAPS_pubeventPreSendRequestContent

Occurs just before ASP.NET sends content to the client.

System_CAPS_pubeventPreSendRequestHeaders

Occurs just before ASP.NET sends HTTP headers to the client.

System_CAPS_pubeventReleaseRequestState

Occurs after ASP.NET finishes executing all request event handlers. This event causes state modules to save the current state data.

System_CAPS_pubeventRequestCompleted

System_CAPS_pubeventResolveRequestCache

Occurs when ASP.NET finishes an authorization event to let the caching modules serve requests from the cache, bypassing execution of the event handler (for example, a page or an XML Web service).

System_CAPS_pubeventUpdateRequestCache

Occurs when ASP.NET finishes executing an event handler in order to let caching modules store responses that will be used to serve subsequent requests from the cache.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIHttpAsyncHandler.BeginProcessRequest(HttpContext, AsyncCallback, Object)

Initiates an asynchronous call to the HTTP event handler.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIHttpAsyncHandler.EndProcessRequest(IAsyncResult)

Provides an asynchronous process End method when the process finishes.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIHttpHandler.ProcessRequest(HttpContext)

Enables processing of HTTP Web requests by a custom HTTP handler that implements the IHttpHandler interface.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIHttpHandler.IsReusable

Gets a Boolean value indicating whether another request can use the IHttpHandler object.

Instances of the HttpApplication class are created in the ASP.NET infrastructure, not by the user directly. One instance of the HttpApplication 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.

HttpApplication is introduced in the .NET Framework version 3.5. For more information, see .NET Framework Versions and Dependencies.

System_CAPS_noteNote

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:

  1. BeginRequest

  2. AuthenticateRequest

  3. PostAuthenticateRequest

  4. AuthorizeRequest

  5. PostAuthorizeRequest

  6. ResolveRequestCache

  7. PostResolveRequestCache

    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.

  8. PostMapRequestHandler

  9. AcquireRequestState

  10. PostAcquireRequestState

  11. PreRequestHandlerExecute

    The event handler is executed.

  12. PostRequestHandlerExecute

  13. ReleaseRequestState

  14. PostReleaseRequestState

    After the PostReleaseRequestState event is raised, any existing response filters will filter the output.

  15. UpdateRequestCache

  16. PostUpdateRequestCache

  17. LogRequest.

    This event is supported in IIS 7.0 Integrated mode and at least the .NET Framework 3.0

  18. PostLogRequest

    This event is supported IIS 7.0 Integrated mode and at least the .NET Framework 3.0

  19. EndRequest

The following two examples demonstrate how to use the HttpApplication 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 HttpApplication event must implement the IHttpModule interface.

using System;
using System.Web;

namespace Samples.AspNet.CS
{
    public class CustomHTTPModule : IHttpModule
    {
        public CustomHTTPModule()
        {
            // Class constructor.
        }

        // Classes that inherit IHttpModule 
        // must implement the Init and Dispose methods.
        public void Init(HttpApplication app)
        {

            app.AcquireRequestState += new EventHandler(app_AcquireRequestState);
			app.PostAcquireRequestState += new EventHandler(app_PostAcquireRequestState);
		}

        public void Dispose()
        {
            // Add code to clean up the
            // instance variables of a module.
        }

        // Define a custom AcquireRequestState event handler.
        public void app_AcquireRequestState(object o, EventArgs ea)
        {
            HttpApplication httpApp = (HttpApplication)o;
            HttpContext ctx = HttpContext.Current;
            ctx.Response.Write(" Executing AcquireRequestState ");
        }

        // Define a custom PostAcquireRequestState event handler.
		public void app_PostAcquireRequestState(object o, EventArgs ea)
		{
			HttpApplication httpApp = (HttpApplication)o;
			HttpContext ctx = HttpContext.Current;
			ctx.Response.Write(" Executing PostAcquireRequestState ");
		}

	}
}

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.CS.CustomHTTPModule"
        name="CustomHttpModule" />
      </httpModules>
  </system.web>
</configuration>

The following setting applies to IIS 7.0 Integrated mode.

<configuration>
  <system.webServer>
    <modules>
      <add type="Samples.AspNet.CS.CustomHTTPModule"
        name="CustomHttpModule" />
      </modules>
  </system.webServer>
</configuration>

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft