Start here. This is the direct spoken answer to practice first.
Why this matters
Middleware and filters both wrap execution, but they operate at different scopes and have access to different framework context. Choosing the right boundary keeps cross-cutting behavior visible and correctly ordered.
Middleware runs at the application pipeline level and can wrap almost the whole request. Filters run closer to MVC controller or endpoint execution and have more information about the selected action or result. I use middleware for broad concerns such as exception handling, correlation IDs, CORS, and authentication. I use filters when the behavior depends on action context or model state.