How to efficiently test if action is decorated with an attribute (AuthorizeAttribute)?

后端 未结 2 1316
无人及你
无人及你 2021-02-02 15:02

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

2条回答
  •  南方客
    南方客 (楼主)
    2021-02-02 15:29

    var hasAuthorizeAttribute = filterContext.ActionDescriptor.IsDefined(typeof(AuthorizeAttribute), false);

    http://msdn.microsoft.com/en-us/library/system.web.mvc.actiondescriptor.isdefined%28v=vs.98%29.aspx

提交回复
热议问题