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 is localhost in asp.net?

0 Answers  


all asp.net interives questions

1 Answers  


What is asp net_sessionid?

0 Answers  


How tooltip is set through code-behind in ASP.NET?

0 Answers  


In which event of the page viewstate is available?

0 Answers  






What are the authentication types in asp.net?

0 Answers  


Can you explain how ASP.NET application life cycle and page life cycle events fire?

0 Answers   MindCracker,


What are validator? Name the Validation controls in asp.net? How do u disable them?

2 Answers  


What are the asp.net 2.0 features?

0 Answers  


How many no of classes in .net

4 Answers  


What are the ways to sending the data in ASP.NET page?

0 Answers  


How you will manage the state of ASP.NET controls?

0 Answers   Sans Pareil IT Services,


Categories