← .NET Core learning path
.NET Core · Module 4 of 10

Middleware pipeline

Process every request through ordered middleware.

📖 Key ideas

  1. Middleware components run in order for each request.
  2. Common: UseHttpsRedirection, UseStaticFiles, UseRouting, UseAuthentication, UseAuthorization.
  3. Custom middleware: app.Use(async (ctx, next) => { ...; await next(); }).
  4. Order matters: authentication before authorization.
  5. Exception handling middleware should come first.
💡 Real-life example: Middleware is a relay race: each runner (component) does its part and passes the baton (request).
MiddlewareComponent in the request pipeline
next()Calls the next middleware
UseAuthenticationIdentifies the user
UseAuthorizationChecks permissions