Custom Action Filter ASP.NET MVC 4

asp.net-mvc, c#

Solution

Prefix your base class with `System.Web.Mvc`, I have a "hunch" you may be using `System.Web.Http.Filters.ActionFilterAttribute` instead.

So then you would have to override

OnActionExecuting(ActionExecutingContext filterContext)

And things will be OK.

And as you can see, `ActionFilterAttribute` implements `IActionFilter` already, so you don't need to specify it.

Problem

This thing is killing me. Basically what I have is the custom ActionFilter (Class which Inherits from ActionFilterAttribute and implements IActionFilter). it looks like this ``` public class ValidationFilterAttribute : ActionFilterAttribute, IActionFilter { public override void OnActionExecuting(HttpActionContext actionContext) { // do some stuff here } } ``` this is what FilterConfig looks like ``` public class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); filters.Add(new ValidationFilterAttribute()); } } ``` But whenever I start the project there is an exception saying following The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter. But obviously the `ValidationFilterAttribute` implements one of those interfaces. Am I missing something very basic here? I can't figure out what is wrong.

Original source