The Anubhav portal was launched in March 2015 at the behest of the Hon'ble Prime Minister for retiring government officials to leave a record of their experiences while in Govt service .
Middleware in ASP.NET Core is a fundamental concept that refers to software components assembled into a
pipeline to handle HTTP requests and responses.
What is Middleware?
Middleware is a piece of code that processes requests coming into the application and
responses going out.
It sits between the server and your application logic.
Each middleware component can:
Inspect the incoming request,
Perform some action (e.g., authentication, logging, routing),
Pass control to the next middleware in the pipeline,
Or short-circuit the pipeline and generate a response directly.
How Middleware Works:
An HTTP request arrives.
It flows through each middleware component in order.
Each middleware can:
Process the request,
Pass control to the next middleware,
Optionally modify the response on the way back.
Common Middleware Examples:
Routing — decides which endpoint handles the request.
Authentication — checks who the user is.
Authorization — checks if the user can access resources.
Static Files — serves files like images, CSS, JS.
Exception Handling — catches and processes errors.
Adding Middleware
Middleware components are added in the Startup.Configure method (or
Program.cs in .NET 6+), using extension methods on IApplicationBuilder:
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Middleware in ASP.NET Core is a fundamental concept that refers to software components assembled into a pipeline to handle HTTP requests and responses.
What is Middleware?
How Middleware Works:
Common Middleware Examples:
Adding Middleware
Middleware components are added in the
Startup.Configuremethod (orProgram.csin .NET 6+), using extension methods onIApplicationBuilder:.UseXYZ()for middleware that passes control on, or.Run()for terminal middleware that ends the pipeline.Why Middleware?
Summary:
app.Use...()inStartup.ConfigureorProgram.cs