Run code after a handler method has been selected, but before model binding occurs.

Run code before the handler method executes, after model binding is complete.

Run code after the handler method executes.

Can be implemented on a page or globally.

Cannot be applied to specific page handler methods.

Code can be run before a handler method executes using the page constructor or middleware, but only Razor Page filters have access to HttpContext. Filters have a FilterContext derived parameter, which provides access to HttpContext. For example, the Implement a filter attribute sample adds a header to the response, something that can't be done with constructors or middleware.

Implement either the synchronous or the async version of a filter interface, not both. The framework checks first to see if the filter implements the async interface, and if so, it calls that. If not, it calls the synchronous interface's method(s). If both interfaces are implemented, only the async methods are be called. The same rule applies to overrides in pages, implement the synchronous or the async version of the override, not both.