โ† .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