The HTTP request pipeline is the ordered chain of ASP.NET Core middleware that processes a request and produces a response. Each component can pass control onward or return a response immediately, stopping later components from running. section 1.2.1
Configure the pipeline with these practical rules:
- Register middleware in processing order; ASP.NET Core evaluates it first in, first out. section 1.2.1
- Place potentially terminal middleware before terminal middleware, because terminal components always end processing. section 1.2.2
- Use HTTPS redirection, authorization, static-file handling, or endpoint mapping according to the responsibility each component provides. section 1.2.1
- Treat Run as fully terminal and normally the final pipeline operation. section 1.2.2
A typical Program.cs pipeline
Build the application, enable Swagger only in development, redirect HTTP to HTTPS, enable authorization, map controllers, and finish with app.Run(). The sequence makes the request path explicit while keeping service registration separate from pipeline configuration. section 1.2.2
var builder = WebApplication.CreateBuilder(args); #1
// Add services to the container.
builder.Services.AddControllers(); #2
// Learn more about configuring Swagger/OpenAPI
// at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); #2
builder.Services.AddSwaggerGen(); #2
var app = builder.Build(); #3
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger(); #4
app.UseSwaggerUI(); #4
}
app.UseHttpsRedirection(); #4
app.UseAuthorization(); #4
app.MapControllers(); #4
app.Run(); #5
Inspect the complete Program.cs listing to see service registration, application construction, environment-specific middleware, endpoint mapping, and the terminal Run call together. section 1.2.2

