Asp.Net MiddleWare vs. HttpModules

Starting with Asp.Net 5, we now have a “middleware” concept for modifying or interacting with a request and response. All this was done before using the HttpModules.

So here is my question.

What is asp.net middleware and what problems are solved by this component, which cannot be addressed using HttpModules?

+4
source share
1 answer

HttpModules act as request filters in ASP.NET versions prior to 5. They are reusable units of code that can be connected to the request pipeline and are tasked with responding to events defined in the HttpApplication class as they are fired.

Middleware can be considered both HTTP modules and handlers , which we used in classic ASP.NET. Some middleware will perform various intermediate tasks when processing requests, such as authentication, retrieving and maintaining session state, logging, etc. Some of them will be the final request handlers, which will give answers.


Ques 2: What problems are solved by this component, which cannot be addressed using HttpModules?

  • In the HttpModule you needed to execute code based on the various stages of the request, such as AuthenticateRequest , AuthorizeRequest , PostResolveRequestCache and others named events slightly vaguely. This no longer applies to Middleware, now everything makes sense. everything is just linear execution of your code. You can have several intermediate environments defined for execution in your application, and each of them is a Startup.cs file.

  • As a developer, you have full control over what is being executed, and in what order, rather than not knowing which HttpModules are running and actually not controlling their order of execution. Middleware can simply change the query and continue calling the next one in, or it can just end the pipeline and return the result.

Link

+5
source

All Articles