我创建了一个自定义ActionFilterAttribute
,并希望在通过某些属性修饰动作时执行某些操作。我可以获得动作方法的属性和控制器的属性。但找不到在FilterConfig
中注册的属性。
如何找到它们?
我的代码是:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new SomeFilterOrAttribute());
}
和
public class BeforeActionAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var actionAttributes = filterContext.ActionDescriptor.GetCustomAttributes(true);
var controllerAttributes = filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(true);
// How can get list of registered global filters or attributes?
}
}
答案 0 :(得分:1)
GlobalFilters
类允许检索和修改全局过滤器集合
//requires "using System.Linq"
var globalFilters = GlobalFilters.Filters.ToList();