最近一直被这个问题所困扰,现在想了一个方案,特贡献出来给大伙,技术不好,还请指教,如有更好的方法,还请告诉我,谢谢。
1 /// <summary> 2 /// 检查是否排除过滤器 3 /// </summary> 4 /// <param name="filterContext">方法执行上下文</param> 5 /// <returns></returns> 6 public bool IsRemoveFilter(ActionExecutingContext filterContext) 7 { 8 bool check = false; 9 string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; 10 if (this.RemoveActionName == null) 11 { 12 check = CustomCompareStrings(RemoveControllerName, controllerName); 13 } 14 else 15 { 16 string actionName = filterContext.ActionDescriptor.ActionName; 17 if (CustomCompareStrings(RemoveControllerName, controllerName)) 18 { 19 check = CustomCompareStrings(RemoveActionName, actionName); 20 } 21 } 22 return check; 23 }
这其中,我自定义了一个比较方法,判断当前的控制器或者action方法是否设置了的排除对象。
1 /// <summary> 2 /// 自定义比较方法 3 /// </summary> 4 /// <param name="useSetValue">用户设置的排除过滤器的值</param> 5 /// <param name="nowPageValue">当前所在页面的ActionName或ControllerName的值</param> 6 /// <returns></returns> 7 publ