I know how to Register Global filter that applies all actions with:
protected void Application_Start(){
GlobalFilters.Filters.Add(new MySweetCustomFiAttribute());
}
But instead, I need to register MySweetCustomFilterAttribute
to actions not having (or having) [ChildActionOnly]
attribute.
// Register MySweetCustomFilterAttribute
public ActionResult Index()
{
return View();
}
// Do not register MySweetCustomFilterAttribute
[ChildActionOnly]
public ActionResult MySweetChildAction()
{
...
}
You should put a bypass into your [MySweetCustomFiAttribute] to return if the action is decorated with [ChildActionOnly]. Like this:
if(filterContext.ActionDescriptor.IsDefined(typeof(ChildActionOnlyAttribute), false))
return;