Reputation: 60694
Maybe I have misunderstood the point of the ActionFilterAttribute, but what I have now is the following:
public class MyCustomAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//do something useful here
}
}
Then in my Home controller, I have the following action methods:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[MyCustom]
public ActionResult Test()
{
return View();
}
}
What I would expect now is that OnActionExecuting
gets fired when I try to access the /Home/Test
, but not when I try to access /Home/Index
.
However, it gets fired for both action methods. I have also verified inside OnActionExecuting
that there is in fact the Index
action that is getting called.
Are there any possibility of having OnActionExecuting
only getting called when you call a action method that is marked with the attribute?
Upvotes: 4
Views: 3129
Reputation: 678
Check whether MyCustomAttribute
is present in GlobalFilters
collection in Global.asax
.
Upvotes: 7