检查ActionFilters在OnActionExecuting中应用了哪些内容?

时间:2012-11-26 02:45:32

标签: c# asp.net-mvc

如何在Controller中的OnActionExecuting中检查应用哪些ActionFilterAttribute?

1 个答案:

答案 0 :(得分:1)

也许它可以帮到你:

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

结果应该是这样的:

enter image description here

<强>更新

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);