0

我有一个自定义属性定义如下,

public class SkipAuthentication : Attribute
{

}

并用它来装饰控制器如下,

[SkipAuthentication]
public class AccountTypeController : Controller
{
    // GET: /AccountType/Create
    [HttpGet]
    public ActionResult Create()
    {
        try
        {
            return View();
        }
        catch (Exception ex)
        {
            ViewBag.ResMessege = ResMessege.getDanger(ex.Message);
            return View();
        }
    }
}

现在我期望它应该应用于控制器内的所有操作,

public class FebTechFilters : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        if (filterContext.ActionDescriptor.GetCustomAttributes(typeof(SkipAuthentication), false).Any())
        {
            return;
        }

        if (null == filterContext.HttpContext.Session.Contents["UserId"])
        {
            filterContext.Result = new RedirectResult("~/Login/Index");
        }

        base.OnActionExecuting(filterContext);
    }
}

但是当我打电话给这个时,filterContext.ActionDescriptor.GetCustomAttributes(typeof(SkipAuthentication), false).Any()我把它理解为false我错过了什么?

4

0 回答 0