Last active
August 6, 2019 21:43
-
-
Save fatagun/1a2c6e88a328e3666742ec3a74aca59a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var controllers = from type in myAssembly.GetTypes() | |
where type.Name.Contains("Controller") | |
where !type.IsAbstract | |
select type; | |
// bunun yerine ITypeLocator kullanabilirsin. | |
// _locator.FindClassesOfType<Controller>(); | |
foreach(var controller in controllers) | |
{ | |
var authorized = controller.GetCustomAttributes(true).Any(e => e.GetType().Equals(typeof(AuthorizeAttribute))); | |
if(authorized) | |
{ | |
var controllerAttrib = controller.GetCustomAttribute(typeof(AuthorizeAttribute)) as AuthorizeAttribute; | |
var controllerName = controller.Name; | |
Console.WriteLine($"{controllerName} - {controllerAttrib.Roles} - {controllerAttrib.Policy} - {controllerAttrib.AuthenticationSchemes}"); | |
var controllerMethods = controller.GetMethods(); | |
foreach (var controllerMethod in controllerMethods) | |
{ | |
var methodName = controllerMethod.Name; | |
var attribute = controllerMethod.GetCustomAttribute(typeof(AuthorizeAttribute)) as AuthorizeAttribute; | |
if(attribute != null) | |
{ | |
Console.WriteLine($"{methodName} - {attribute.Roles} - {attribute.Policy} - {attribute.AuthenticationSchemes}"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment