Is it possible to list the names of all controllers and their actions programmatically?
I want to implement database driven security for each controller and action.
You can use reflection to find all Controllers in the current assembly, and then find their public methods that are not decorated with the NonAction
attribute.
Assembly asm = Assembly.GetExecutingAssembly();
asm.GetTypes()
.Where(type=> typeof(Controller).IsAssignableFrom(type)) //filter controllers
.SelectMany(type => type.GetMethods())
.Where(method => method.IsPublic && ! method.IsDefined(typeof(NonActionAttribute)));