The ASP.NET Pipeline & Kestrel
When you write app.MapGet(...) in ASP.NET Core, a lot happens before your code runs - and almost nobody
learns what. This is the roots guide for ASP.NET Core: underneath the
minimal APIs and controllers sit a web server (Kestrel), a middleware pipeline that every request
flows through, and a host that wires up configuration and the dependency-injection container. Learn
these and the framework stops being a pile of conventions and becomes a small, legible machine.
The mental model is a server, a pipeline, and a host. Kestrel is the cross-platform web server that
actually listens on the socket and speaks HTTP. Each request it accepts runs through the middleware
pipeline - an ordered chain of functions, each a RequestDelegate that can do work, call the next
one, and act on the way back out (your endpoint is the end of the chain). And the host is the object
that builds it all: it reads configuration, sets up the DI container, and starts Kestrel. Hold "Kestrel
listens, the pipeline processes, the host wires it together," and every app.Use(...) and
builder.Services... line has an obvious home.
📝 This is a roots guide - it assumes C# (C# From Zero) and is most rewarding after you've used ASP.NET Core, so the pieces have somewhere to land. It's the .NET parallel to the net/http roots guide (Go) and WSGI & ASGI (Python). Examples run as .NET programs.
How to read this
Short and foundational - read in order. It builds from "what Kestrel is" up through the pipeline, the host, and how minimal APIs/MVC sit on top. Phases carry difficulty badges.
The phases
- What Kestrel & the Pipeline Are 🟢 - the server, the pipeline, and the host, and how a request flows.
- Kestrel: The Web Server 🟡 - the cross-platform server, the listener, and reverse proxies.
- The Middleware Pipeline 🟡 -
Use/Run/Map, ordering, and short-circuiting. - The RequestDelegate 🔴 - what middleware really is: a function that wraps the next one.
- The Host, DI & Configuration 🔴 -
WebApplication/the generic host, the service container, and config sources. - How Minimal APIs & MVC Sit on Top 🟢 - endpoint routing, and where your handlers plug in.
- Where to Go Next 🟢 - applying this to real apps, performance, and the ecosystem.
The throughline: Kestrel listens, a middleware pipeline of
RequestDelegates processes each request, and the host wires up DI + configuration + the server. That's the machine inside every .NET web app.