The general case we just put the Attribute on the Contoller top. like:
[Authorize]
public class XXController : Controller
{
}
But because My project need use the third part binary DLL. we don't have the source code for change the original controller on the binary dll, but we can ignore the default authorize use some setting for it, then I just want to know Is there possible to add custom Authorize Attribute to for the XXController use code?
This is my CustomAuthorizeAttribute:
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
public bool IsOnlyAdminAccess {get ;set;}
public override void OnAuthorization(AuthorizationContext filterContext)
{
if (Session.IsAdmin && !IsOnlyAdminAccess )
{
// redirect
}
}
}
So now I think Is there Maybe on global.aspx. use some way like(just idea) add the CustomAuthorizeAttribute for the specific Controller:
AddCustomAttributeWayOrMethod(XXController, new CustomAuthorizeAttribute(IsOnlyAdminAccess = true));
Some friend maybe said I just add it to GlobalFilterCollection , like:
GlobalFilterCollection.Add(new CustomAuthorizeAttribute ());
But I already add it for global controller. I just need my XXController use IsOnlyAdminAccess = true property, other controller all don't need that.