what are httphandlers and httpmodules.and their differences.



what are httphandlers and httpmodules.and their differences...

Answer / nilesh

Http Handlers


HTTP handlers are the .NET components that implement the System.Web.IHttpHandler interface. Any class that implements the IHttpHandler interface can act as a target for the incoming HTTP requests. HTTP handlers are somewhat similar to ISAPI extensions. One difference between HTTP handlers and ISAPI extensions is that HTTP handlers can be called directly by using their file name in the URL, similar to ISAPI extensions.

HTTP handlers implement the following methods.

ProcessRequest:This method is actually the heart of all http handlers. This method is called to process http requests.

IsReusable:This property is called to determine whether this instance of http handler can be reused for fulfilling another requests of the same type. HTTP handlers can return either true or false in order to specify whether they can be reused.

These classes can be mapped to http requests by using the web.config or machine.config file. Once that is done, ASP.NET will instantiate http handler whenever the corresponding request comes in.

HTTP Modules


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:

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.


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.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More ASP.NET Interview Questions

What are the page life cycle events?

0 Answers  


Will the asp.net validators run in server side or client side? How do you do client-side validation in .net? How to disable validator control by client side javascript?

0 Answers  


Which protocol is used in a web api?

0 Answers  


What is the server of asp.net?

0 Answers  


in which protocol ASP.NET WEB API Work?

0 Answers   HCL,






What is Difference between Callbacks and Postback in ASP.NET?

11 Answers  


i have a register form & in that form i have a 2 textboxes for entering name&age.my doubt is that how can i provide error message like "invalid entry" when user enter a invalid name/age(eg:user enter name as #%%%##daff,and age as 1000.)in that textboxes.I want code.

3 Answers  


How ASP and ASP.NET page works? Explain about asp.net page life cycle?

0 Answers  


What is the difference between application object and session object?

4 Answers   IBS,


What is customer control and user control?

1 Answers   Perot Systems,


.Net Doesn't offer Deterministic Distruction ? a) True b) False

4 Answers   CTS,


How to remove cache object in asp.net?

2 Answers   TVS,


Categories