Order of middleware: why it matters?
Middleware is executed in the order it's added, and this order affects
behavior.
Example:
app.UseAuthentication(); // Must come before authorization
app.UseAuthorization();
app.UseEndpoints(...);
Logging, error handling, and security middlewares must be early
in the pipeline.