I learnt the hard way that filters (in my case a PageFilter) are honored only if they are decorated on the page model and not on handler methods, like in MVC.
The documentation on IPageFilter is also not super clear: A filter that surrounds execution of a page handler method.
PageApplicationModelProvider throw an exception to indicate that filters on handler methods are not supported?Could PageApplicationModelProvider throw an exception to indicate that filters on handler methods are not supported?
We generally don't write code to verify users aren't doing things that we don't support. An analyzer does seem like something we could cook up.
The documentation on IPageFilter is also not super clear: A filter that surrounds execution of a page handler method.
Sounds like an easy fix. @Rick-Anderson also recently wrote a doc article about using these filters here - https://docs.microsoft.com/en-us/aspnet/core/mvc/razor-pages/filter?view=aspnetcore-2.1. We could certainly call that out in the docs (it doesn't right now).
You can close this now, I merged https://github.com/aspnet/Docs/pull/6010
I would keep this open. If not an analyzer, we should update the docs on the api to say so. Found the docs needs to be fixed anyway (removing before the action method is invoked)
https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/IPageFilter.cs#L24
@kichalla, let's update the code comment as it's tiny no code change.
Most helpful comment
We generally don't write code to verify users aren't doing things that we don't support. An analyzer does seem like something we could cook up.
Sounds like an easy fix. @Rick-Anderson also recently wrote a doc article about using these filters here - https://docs.microsoft.com/en-us/aspnet/core/mvc/razor-pages/filter?view=aspnetcore-2.1. We could certainly call that out in the docs (it doesn't right now).