Is there a way to have an action filter, like
public class MyActionFilterAttribute : ActionFilterAttribute {
public override void OnActionExecuting(ActionExecutingContext context) {
...
be automatically applied to all actions in a web site?
I don't believe there is an out-of-the-box way to do this. The easiest thing to do for simple sites is just apply the filter at the Controller level. This is pretty common, and generally it's a good idea to have your own base controller class in case things like this crop up where you want to propagate it to all your controllers. E.g.:
[MyActionFilter]
public class MyBaseController : Controller
{
...
}
public class HomeController : MyBaseController
{
...
}
That being said, here is a blog post showing how you can achieve application wide action filters. Looks like a small amount of work, but perhaps you can use this technique.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With