ASP.NET Core Tutorial – Session 7- Middleware, HTTP Pipeline

Session7 ASP.NET Core Middleware & HTTP Pipeline

In this session of ASP.NET Core tutorial, we intend to introduce and explain Middleware. Moreover, we are going to talk about Request Response HTTP which is known as HTTP Pipeline. For better understanding we will show you this, in practice during the video.


Totally, Middleware is small application/software that processes HTTP Request and Response. They have been explained in Configure method in Startup class. There are different types of Middleware and each of them has distinctive role and especial process on Request and Response HTTP.

Middleware has access to both Request and Response. Some of the Requests may pass Middleware without any process. In this case, Middleware has no relation with that Request, for instance, Static File passes UseAuthentication Middleware without any processing. In addition, some Middleware could do proper process on Request and Response then send Request or Response to next/previous Middleware.

Also, some Middleware caused short-circuit and Request will not transit to next middleware. In fact they are Terminal Middleware; so, Response goes back to previous Middleware like: Run Middleware and UseEndpoints Middleware.
Below code shows default Middleware of a ASP.NET Core Empty Web App project.

As you see, in above code, there are three default Middleware in a ASP.NET Core Empty Web App project.

  • app.UseDeveloperExceptionPage: In order to display developer exception page which has been performed in Development Hosting Environment.
  • app.UseRouting: In order to routing in project.
  • UseEndpoints: In this project, this is a Terminal Middleware which display message on browser page.

As it is mentioned, each Request has been processed considering the order, they have been added. In case of being in Development stage, Request first refer to UseDeveloperExceptionPage Middleware, then goes to UseRouting Middleware to process and finally refers to UseEndpoint Middleware. After that, Response passes these procedure vise versa till final result, shown on browser.

HTTP Request and Response Pipeline

ASP.NET Core Request Response Pipeline

Above picture, shows HTTP Request/Response cycle in ASP.NET Core. This cycle implies process of each Request by Middleware , considering the order of adding to program. This procedure is reversed in Response. In other word, at the beginning, Request has been processed by Middleware1, then when it gets Next function request will pass to Middleware2. After processing in this stage, request will pass from Middleware2 to Middleware3 which is Terminal Middleware. Now, Response has been processed by Middleware3 and the procedure will be reversed.

Below code shows you this procedure in practice. The result proves above mentioned pipeline.

For better understanding of this procedure, we explain it by graph:

ASP.NET Core Request Response Pipeline Example

If you need more details, watch this session video. Also, for being updated about our coming sessions, follow us on Instagram, Facebook, Telegram or YouTube and be in touch with us here.

You can download this Session Slides form HERE

0.00 avg. rating (0% score) - 0 votes


0 0 votes
Article Rating

Inline Feedbacks
View all comments