shenku
shenku

Reputation: 12438

Check what ActionFilters applied within OnActionExecuting?

How can I check what ActionFilterAttributes are applied from within OnActionExecuting in my Controller?

Upvotes: 0

Views: 130

Answers (1)

testCoder
testCoder

Reputation: 7385

Maybe it helps you:

 [HttpGet]
 public ActionResult Index()
 {
      var attributes = Attribute.GetCustomAttributes(typeof(HomeController).GetMember("Index").First());
      return View();
 }

And result hould be like this:

enter image description here

UPDATE

var onlyActionFilterAttributesForClass =
                    typeof(HomeController).GetCustomAttributes(true).Where(
                        x => x as ActionFilterAttribute != null);

var onlyActionFilterAttributesForMember = Attribute.GetCustomAttributes(typeof (HomeController).GetMember("Index").First()).
                    Where(
                        x => x as ActionFilterAttribute != null);

Upvotes: 1

Related Questions