Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use HttpHandlers and HttpModules?

When exactly to use HttpHandlers and HttpModules?

Can't I write that code in ASPX pages' code behind?

like image 801
Manish Avatar asked Dec 23 '10 09:12

Manish


People also ask

What is the use of HTTPHandlers when to use this?

HTTPHandlers are used by ASP.NET web application server to handle specific requests based on extensions. HTTPHandlers run as processes in response to a request made to the ASP.NET website. It is a class that implements the System.

What is the difference between middleware and HttpModule?

Both Middleware and HttpModule are pieces of code blocks which lets two or more components interact together during a request execution. HttpModules are registered in the web. config file of the ASP.NET framework while a Middleware is registered via code inside an ASP.NET Core application.

What is HTTP handler and HttpModule in MVC?

To explain HTTP Modules and HTTP Handlers, HTTP module and HTTP handler are used by MVC to inject pre-processing logic in the request chain. HTTP Handlers are extension based pre-processor whereas HTTP Module are event based preprocessor.

What is HTTP handler HTTP modules and middle ware?

HttpModules helps you to attach code specific to a application events. HttpModules are tied to System. web. Middleware are configured in Startup.cs code rather than web.config file (entry point for application) Unlike HttpModules, there is full control of what get's executed and in what order.


1 Answers

HttpModule allows you to intercept the request (before it is handled by its handler) and response generated. It can modify both request/response if needed. ASP.NET sessions, profiles, authentication etc is also implemented as HttpModule - these module inspects the request and attach necessary context (e.g. session state based on session cookie) to the request. Such functionality is difficult to achieve via aspx code behind.

HttpHandler is the one responsible for handling the request i.e. to generate HTTP response which often (but not always) means generating some html. The page class (base for aspx) is nothing but http handler (so are other end points such as asmx, ashx, axd). The raw handler (ashx) is useful when you need absolute control over response generation - it would be possible to use aspx instead but then it would unnecessarily involve all default page/control machinery (view-state, post-date, control tree etc).

like image 160
VinayC Avatar answered Nov 21 '22 02:11

VinayC