Overview

ASP.NET Core middleware are software components assembled into an application pipeline to handle requests and responses. Each component can:

Key concepts

ConceptDescription
RequestDelegateRepresents the next middleware in the pipeline.
HttpContextEncapsulates all HTTP-specific information about an individual HTTP request.
Use/RunExtension methods on IApplicationBuilder to add middleware.
Terminal middlewareMiddleware that does not call next(), ending the pipeline.

Getting started

To add middleware, use the Configure method in Startup.cs (or Program.cs in minimal hosting):

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
});

app.Run();

Read the Creating Middleware page for a step‑by‑step guide on building custom middleware.