我有一个定义如下的自定义属性,
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
我想念的是什么?