Wednesday, November 6, 2019

Hello and As-Salaam U Alikum! , In this article we will learn about the Middleware in asp.net core .

In the Previous versions of Asp.net we had HttpModules and HttpHandler that was used for handling request pipeline, But now in asp.net core we have a newly concept thing which is " Middle Ware ".






What is Middle ware ?


A middle ware is just a component (class) of application that executes on every request of application.we can have more than one middle-ware in our application.It can any middle-ware like custom or framework provided or whether added through Nuget package Developer can set the arrangement of middle-ware in order to execute request pipeline. Each middle ware handle http request and pass control to the next middle ware  as shown in Figure below.



Where To Use Middle ware Components ?

  1. A middle-ware can be used to authenticate a user
  2. Another middle-ware can be used to Authorized the user role.
  3. A middle-ware can be used to log the request and response
  4. A middle-ware can be used to handle the errors
  5. A middle-ware can be used to serve static files like Javascript ,Css , Images etc

Short Circuiting Request Pipeline:

It is a concept in which one middle-ware decides not to call the next middle-ware component in the request pipline. for Example: If the request is coming for an static file such as an image, than that static file middle-ware component handles the request and short circuits the request & not pass the request to the next component i.e mvc Middle-ware component


Execution Order middle-ware Component:

Asp.net core middle-ware executes in the same order as they are added to pipeline, so the developer should take care of adding the middle-ware in the right order.

Configure middle-ware Component:

We need to configure the middle-ware in configure method which is present in Startup.cs file.

Request Delegate in asp.net Core:

Request delegates are used to handle each incoming request ,we can configure the request delegate by using map,run & use extension method
Conclusion:
thats not all about the Middle-ware , we will discuss more about the middle-ware in out next article, Thank you for reading. Have a good day.

0 Comments:

Post a Comment

Do not Add Spam links in the Comment Box

Subscribe to Post Comments [Atom]

<< Home