An ASP.NET Core request pipeline is an ordered chain of middleware that receives HTTP requests and produces responses. For each request, the platform passes request and response objects through the chain. A component may inspect the request, change the response, or pass control onward. Components can also inspect and modify the response on its return path. If none produces a response, ASP.NET Core returns HTTP 404 Not Found. section 12.2.1 section 12.6
Configure the pipeline in Program.cs after building the application. Service registrations on builder.Services make objects available to the application; middleware registrations on app determine how requests are handled. Registration order deserves attention: changing the sequence can change which component gets a request and whether later components run. section 7.1.5 section 12.0
Three common pipeline decisions are:
- Serve static content with app.UseStaticFiles(). Endpoint routing is added automatically; app.MapDefaultControllerRoute() registers MVC endpoints using its default route convention. section 7.1.5
- Add custom middleware with Use or UseMiddleware. It can generate a response, pass the request to the next component, or short-circuit processing. Different URL paths can use different middleware sequences. section 12.0 section 12.6
- Register supporting services as well as middleware when a feature needs both. Sessions, for example, require a session service and app.UseSession(); the example also registers an in-memory cache. section 16.3.1
Listing 13.3 Replacing the contents of the Program.cs file in the Platform folder
using Platform;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseMiddleware<Population>();
app.UseMiddleware<Capital>();
app.Run(async (context) => {
await context.Response.WriteAsync("Terminal Middleware Reached");
});
app.Run();
This Program.cs listing makes the order tangible: Population runs before Capital, followed by terminal middleware that writes a response if processing reaches it. section 13.1
Handle a URL or pass it on
A Population middleware checks paths such as /population/london and writes a response when it recognizes one. Otherwise, it passes the request onward. A later Capital middleware handles paths such as /capital/france; the example can be run with dotnet run and checked at http://localhost:5000/population/london and http://localhost:5000/capital/france. For a smaller setup check, TestMiddleware writes product, category, and supplier counts at /test and forwards other paths. section 13.1 section 18.4
The same configuration pattern extends beyond hand-written responses. A pipeline can serve an MVC application or deliver Blazor WebAssembly content under /webassembly. When a request behaves unexpectedly, inspect the registered components, their order, and the endpoint or path they are intended to handle. section 7.1.5 section 37.2.6 section 12.0

