Middleware

Each component:

  • Chooses whether to pass the request to the next component in the pipeline.

  • Can perform work before and after the next component in the pipeline.

The request handling pipeline is composed as a series of middleware components. Each component performs asynchronous operations on an HttpContext and then either invokes the next middleware in the pipeline or terminates the request.

Example of a middleware class:

Add middleware to pipeline:

When a delegate doesn't pass a request to the next delegate, it's called short-circuiting the request pipeline. Short-circuiting is often desirable because it avoids unnecessary work. For example, Static File Middleware can act as a terminal middleware by processing a request for a static file and short-circuiting the rest of the pipeline.

Last updated