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.