Q:

Implementation MVC action OnAuthorization attr, which skip OnAuthorization attr in controller

I have auth attribiute to controll access to controller
public class UserLevelAccessibilityAttribute : FilterAttribute, IAuthorizationFilter
{ 
       var baseController = filterContext.Controller as Controllers.BaseController;

        var userContext = baseController.UserContext;
        if (false == userContext.HasUserLevels(_levels))
        {
            var postData = new Dictionary<string, object>();
            postData.Add("requiredLevels", string.Join(",", _levels));

            filterContext.Result = 
                new RedirectAndPostActionResult("/Error/Unauthorized", postData);
       }
}

In code it looks like
[UserLevelAccessibilityAttribute(EPermissionLevel.Pricing)]
public MyContr : Controller
{
    [SkipAuthorizationFromController]
    public ActionResult MyAction()
    {
    }
 }

My question is how to implement SkipAuthorizationFromController attribute to skip controller's authorization? Or should I change UserLevelAccessibilityAttribute implementation?

A:

in your custom attribute check if there is any SkipAuthorizationFromController attribute present on the action.
you can use below to do that
     actionContext
       .ActionDescriptor
       .GetCustomAttributes<SkipAuthorizationFromController>()
       .Any()

