This is my CustomAuthorizeAttribute class:
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
public string ControllerName { get; set; }
public override void OnAuthorization(AuthorizationContext filterContext)
{
if (ControllerName != "pass")
{
// stop or redirect
}
}
}
I register it to global filters for all controller can use:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new AdminAuthorizeAttribute());
}
For some specific Action I add it with the param ControllerName :
[AdminAuthorize(ControllerName="pass")]
public ActionResult Index()
{
return View();
}
But the problem is now in the OnAuthorization(), the ControllerName is always get null when execute the specific Action.
Is that because I can't use the global authorizeAttribute and same Attibute for some specific Action together?? Why? I always thought if I add some AuthorizeAttribute for specific Action, and add the Attribute to global filter , the specific Action will get height priority.
Update1:
If the problem source is 2 authorized all execute. then How do I override the global authorized filter when I add a same AuthorizeAttribute for Some Action? (only different is the param, I just want it ignore the global authorized when I add one for some Action)