.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Post New Resource Bookmark and Share   

HTTP Modules

Posted By:Shashi Ray       Posted Date: December 29, 2009    Points: 25    Category:    URL: http://www.dotnetspark.com  
 

 

HTTP modules are .NET components that implement the System.Web.IHttpModule interface. These components plug themselves into the ASP.NET request processing pipeline by registering themselves for certain events. Whenever those events occur, ASP.NET invokes the interested HTTP modules so that the modules can play with the request.

An HTTP module is supposed to implement the following methods of the IHttpModule interface:

Method Name

Description

Init

This method allows an HTTP module to register its event handlers to the events in the HttpApplication object.

Dispose

This method gives HTTP module an opportunity to perform any clean up before the object gets garbage collected.

 

 An HTTP module can register for the following events exposed by the System.Web.HttpApplication object.

Event Name

Description

AcquireRequestState

This event is raised when ASP.NET runtime is ready to acquire the Session state of the current HTTP request.

AuthenticateRequest

This event is raised when ASP.NET runtime is ready to authenticate the identity of the user.

AuthorizeRequest

This event is raised when ASP.NET runtime is ready to authorize the user for the resources user is trying to access.

BeginRequest

This event is raised when ASP.NET runtime receives a new HTTP request.

Disposed

This event is raised when ASP.NET completes the processing of HTTP request.

EndRequest

This event is raised just before sending the response content to the client.

Error

This event is raised when an unhandled exception occurs during the processing of HTTP request.

PostRequestHandlerExecute

This event is raised just after HTTP handler finishes execution.

PreRequestHandlerExecute

This event is raised just before ASP.NET begins executing a handler for the HTTP request. After this event, ASP.NET will forward the request to the appropriate HTTP handler.

PreSendRequestContent

This event is raised just before ASP.NET sends the response contents to the client. This event allows us to change the contents before it gets delivered to the client. We can use this event to add the contents, which are common in all pages, to the page output. For example, a common menu, header or footer.

PreSendRequestHeaders

This event is raised just before ASP.NET sends the HTTP response headers to the client. This event allows us to change the headers before they get delivered to the client. We can use this event to add cookies and custom data into headers.

ReleaseRequestState

This event is raised after ASP.NET finishes executing all request handlers.

ResolveRequestCache

This event is raised to determine whether the request can be fulfilled by returning the contents from the Output Cache. This depends on how the Output Caching has been setup for your web application.

UpdateRequestCache

This event is raised when ASP.NET has completed processing the current HTTP request and the output contents are ready to be added to the Output Cache. This depends on how the Output Caching has been setup for your Web application.

Apart from these events, there are four more events that we can use. We can hook up to these events by implementing the methods in the global.asax file of our Web application.

These events are as follows:

  • Application_OnStart
    This event is raised when the very first request arrives to the Web application.
  • Application_OnEnd
    This event is raised just before the application is going to terminate.
  • Session_OnStart
    This event is raised for the very first request of the user's session.
  • Session_OnEnd
    This event is raised when the session is abandoned or expired.


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend