I\'m using MVC and have a situation where in my OnActionExecuting()
I need to determine if the Action method that is about to execute is decorated with an attribute
You can simply use filterContext.ActionDescriptor.GetCustomAttributes
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
bool hasAuthorizeAttribute = filterContext.ActionDescriptor
.GetCustomAttributes(typeof(AuthorizeAttribute), false)
.Any();
if (hasAuthorizeAttribute)
{
// do stuff
}
base.OnActionExecuting(filterContext);
}