Middleware là các C# class xử lý HTTP request/response theo pipeline.
- Mỗi middleware nhận request, có thể sửa đổi nó, chuyển tiếp cho middleware tiếp theo qua
next(), rồi xử lý response trên đường về. - Middleware phổ biến: authentication, authorization, logging, CORS.
- Thứ tự rất quan trọng — exception handler đặt trước, CORS trước auth, auth trước authorization.
Middleware are C# classes that process HTTP requests and responses in a pipeline.
- Each middleware receives a request, optionally modifies it, passes it to the next middleware via
next(), then handles the response on the way back. - Common middleware: authentication, authorization, logging, CORS.
- Order matters — exception handlers first, CORS before auth, auth before authorization.