ASP.NET Coreworking

What is the ASP.NET Core middleware pipeline?

Describe order, short-circuiting, and how you would place authentication relative to endpoints.

Points worth saying

  • Middleware is a chain. Each component chooses whether to call the next one.
  • Order is behavior. Authentication runs before authorization, and endpoints run after routing.
  • Use middleware for cross-cutting work and filters or endpoints for resource-specific work.

A full answer

The pipeline is a sequence of delegates built at startup. A request enters at the first middleware. That component can write to the response, mutate the HttpContext, and either call the next delegate or stop.

Routing finds the endpoint. Authentication establishes the user. Authorization decides whether that user may continue. The endpoint then runs. If you put authorization before authentication, the user is still anonymous and legitimate requests fail.

Exception handling and request logging belong early, so they observe the rest of the chain. Caching and compression belong where their headers are still meaningful. Static files often sit before routing so known assets never enter MVC.

Choose middleware when every request, or a wide slice of requests, needs the same work. Choose an endpoint filter when the work belongs to one route. That distinction keeps the pipeline readable.

Mark your progress

Create a practice profile to mark this question.