Как определить фильтр действий, используемый в методе действия контроллера?

OnActionExecuting срабатывает, когда действие вот-вот будет выполнено.

Если у моего действия есть фильтр действий


[myCustomActionFilter]
public ActionResult MyAction()
{
//implementation
}

Можно ли определить (внутри события OnActionExecuting), что к действию применено myCustomActionFilter?


person h3n    schedule 08.06.2010    source источник


Ответы (1)


Описанный выше метод чувствителен к регистру.

public void OnActionExecuting(ActionExecutingContext filterContext)
{
    var actionDescriptor = filterContext.ActionDescriptor;
    if (actionDescriptor.IsDefined(typeof(myCustonActionFilter), true))
    {
        var attributeInstance = (myCustomActionFilter) actionDescriptor.GetCustomAttributes(typeof(myCustomActionFilter), true);

    }   
}
person Ivan Butsyrin    schedule 23.06.2010