日期:2014-05-17  浏览次数:20408 次

MVC过滤器,如何排除某个Action不使用Controller上的过滤器
有什么办法呢?求各位大神支招。 在Controller上设置了过滤器,怎样排除控制器下的某些action不使用Filter即过滤器。
mvc filter

------解决方案--------------------
新增过滤对象,如:
[AttributeUsage(AttributeTargets.Method)]
public class NoFilterAttribute : Attribute { }

Action头部标识该属性[NoFilter]

原过滤器新增判断条件是否有NoFilter属性
object[] attrs = filterContext.ActionDescriptor.GetCustomAttributes(typeof(NoFilterAttribute), true);
if (attrs.Length == 1)//有NoFilter属性
{
//逻辑处理
}