Middleware xử lý tất cả request trước khi routing, dùng cho cross-cutting concerns toàn cục (logging, CORS, exception handling).
- Action filter chỉ chạy trên controller action đã được match, có quyền truy cập vào action context và parameters — dùng cho logic controller-specific (authorization, validation, caching).
- Middleware chạy sớm hơn và rộng hơn; filter chính xác hơn.
Middleware processes all requests before routing and is used for global cross-cutting concerns (logging, CORS, exception handling).
- Action filters run only on matched controller actions with access to action context and parameters, making them suitable for controller-specific logic (authorization, validation, caching).
- Middleware executes earlier and globally; filters are more targeted.