Skip to content

Instantly share code, notes, and snippets.

@ithielnor
Created November 4, 2014 20:41
Show Gist options
  • Save ithielnor/9a0cf811b2a7bf88ecfe to your computer and use it in GitHub Desktop.
Save ithielnor/9a0cf811b2a7bf88ecfe to your computer and use it in GitHub Desktop.
var actionLevelAttributes = actionDescriptor.GetFilterAttributes(true);
var controllerLevelAttributes = controllerType.GetCustomAttributes(true);
var assocAttribute = actionLevelAttributes.OfType<AssociationAttribute>().Union(controllerLevelAttributes.OfType<AssociationAttribute>()).FirstOrDefault();
var moduleAttribute = actionLevelAttributes.OfType<ModuleAttribute>().Union(controllerLevelAttributes.OfType<ModuleAttribute>()).FirstOrDefault();
var permissionAttribute = actionLevelAttributes.OfType<RequiresPermissionAttribute>().Union(controllerLevelAttributes.OfType<RequiresPermissionAttribute>()).FirstOrDefault();
if ((assocAttribute != null && !assocAttribute.Authorized())
|| (moduleAttribute != null && !moduleAttribute.Authorized())
|| (permissionAttribute != null && !permissionAttribute.Authorized()))
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment