← .NET Core learning path.NET Core · Module 4 of 10
Middleware pipeline
Process every request through ordered middleware.
📖 Key ideas
- Middleware components run in order for each request.
- Common: UseHttpsRedirection, UseStaticFiles, UseRouting, UseAuthentication, UseAuthorization.
- Custom middleware: app.Use(async (ctx, next) => { ...; await next(); }).
- Order matters: authentication before authorization.
- 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