。NET MVC [AllowAnonymous] 跳过授权过滤器

/// <summary>
    /// 自定义Action过滤器:垃圾回收
    /// </summary>
    [AttributeUsage(AttributeTargets.All, AllowMultiple = true)]//多次调用
    public class CustomDisposeFilter : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //判断是否跳过授权过滤器
            if (filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true)
                || filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true))
            {
                return;
            }
            base.OnActionExecuted(filterContext);
            GC.Collect();
        }
    }
上一篇:MVC过滤器Attribute


下一篇:MVC及MVC Core在filter中如何获取控制器名称和Action名称