ASP.NET Core Pipeline Overview
Understand how requests flow through the middleware pipeline, HttpContext, and how responses are built up.
The Request Pipeline
Every HTTP request in ASP.NET Core flows through a middleware pipeline. Each piece of middleware can inspect, modify, short-circuit, or forward the request to the next component. Understanding this pipeline is fundamental to building ASP.NET Core apps.
HttpContext: The Request Envelope
HttpContext carries everything about a request and response: headers, cookies, body, user claims, connection info, and the cancellation token. All middleware operates on it.
app.Use(async (context, next) =>
{
// Read request info
var method = context.Request.Method;
var path = context.Request.Path;
var headers = context.Request.Headers;
var user = context.User.Identity?.Name;
// Write to response
context.Response.Headers.Append("X-Processed-By", "MyMiddleware");
await next(context); // forward to next middleware
});All lessons in this course
- ASP.NET Core Pipeline Overview
- Writing Custom Middleware
- Short-Circuiting & Branching
- Middleware Ordering & Built-in Middleware