← All notes

ASP.NET Core middleware runs as an ordered pipeline built with Use, Map and Run

Answer: The ASP.NET Core request pipeline is a sequence of request delegates called one after the other. Each middleware chooses whether to pass the request to the next one, and can work before and after it. Build the pipeline with the Use, Map and Run extension methods.

Example

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.Use(async (context, next) =>
{
    // before
    await next.Invoke(context);
    // after (do not write to the response here)
});
app.Map("/status", b => b.Run(ctx => ctx.Response.WriteAsync("ok")));
app.Run(async context => await context.Response.WriteAsync("Hello world!"));
app.Run();

Rules

Branching

Map branches the pipeline by request path. UseWhen branches on a predicate; unlike MapWhen, its branch is rejoined to the main pipeline if it has no terminal middleware.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Microsoft Learn (ASP.NET Core docs), ASP.NET Core Middleware; dotnet/AspNetCore.Docs (GitHub), ASP.NET Core Middleware (source page). CC-BY-4.0 (https://raw.githubusercontent.com/dotnet/AspNetCore.Docs/main/LICENSE). Copyright Microsoft Corporation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Microsoft Learn (ASP.NET Core docs), ASP.NET Core Middleware; dotnet/AspNetCore.Docs (GitHub), ASP.NET Core Middleware (source page). CC-BY-4.0 (https://raw.githubusercontent.com/dotnet/AspNetCore.Docs/main/LICENSE). Copyright Microsoft Corporation.

Cite this

Permanent ID: iil:note:kd7v4fyv

iinventedlight. 2026. "ASP.NET Core middleware runs as an ordered pipeline built with Use, Map and Run." iinventedlight Library, iil:note:kd7v4fyv, version of 2026-11-18. https://iinventedlight.com/library/notes/aspnetcore-middleware/. License: CC-BY-4.0.

@misc{iil_note_kd7v4fyv,
  author = {{iinventedlight}},
  title = {{ASP.NET Core middleware runs as an ordered pipeline built with Use, Map and Run}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/aspnetcore-middleware/},
  note = {Permanent ID iil:note:kd7v4fyv. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/aspnetcore-middleware.md.