.NET › ASP.NET Core Middleware & Request Pipeline
How does UseRouting and endpoint routing (via MapControllers, MapGet, etc.) fit into the middleware pipeline conceptually?
AdvancedAnswer
UseRouting middleware examines the incoming request and matches it against registered endpoint patterns, storing the matched endpoint on the HttpContext but not yet executing it. Middleware registered after UseRouting but before the endpoint execution point (implicitly at the end, or explicitly via UseEndpoints in older syntax) can inspect the matched endpoint's metadata (like authorization requirements) before the actual controller action or minimal API handler finally runs.
app.UseRouting(); // matches request to an endpoint, stores it on HttpContext
app.UseAuthorization(); // can inspect endpoint metadata (e.g., [Authorize]) before execution
app.MapControllers(); // implicitly marks where matched endpoints actually executeReal-world example The [Authorize] attribute on a controller action works because UseAuthorization middleware, running after UseRouting, reads that action's endpoint metadata to decide whether to allow the request through to actual execution.