과 같은 작업을 수행 할 수 있습니다 기대했다입니다 방법 당신이 Assembly.GetExportedTypes()
하여 프로젝트의 모든 컨트롤러를 찾을 만 하위를 필터링해야 목표를 달성하기위한 컨트롤러 Asp.net Mvc: List all the actions on a controller with specific attribute 또는 Accessing the list of Controllers/Actions in an ASP.NET MVC application 에서 모든 작업을 얼마나 ControllerBase
의 클래스와 각 컨트롤러에 대해 두 번째 링크의 new ReflectedControllerDescriptor(typeof(TController)).GetCanonicalActions()
을 호출하십시오. 당신은 메뉴 시스템를 체크 아웃 MVC Sitemap Provider 필요한 경우
public static List<String> GetActions(Type controller)
{
// List of links
var items = new List<String>();
// Get a descriptor of this controller
var controllerDesc = new ReflectedControllerDescriptor(controller);
// Look at each action in the controller
foreach (var action in controllerDesc.GetCanonicalActions())
{
// Get any attributes (filters) on the action
var attributes = action.GetCustomAttributes(false);
// Look at each attribute
var validAction =
attributes.All(filter => !(filter is HttpPostAttribute) && !(filter is ChildActionOnlyAttribute));
// Add the action to the list if it's "valid"
if (validAction)
items.Add(action.ActionName);
}
return items;
}
, 그것은 렌더링하는 무엇을 당신에게 절대 제어를 제공합니다 :
var controllers = Assembly.GetCallingAssembly().GetTypes().Where(type => type.IsSubclassOf(typeof(Controller))).ToList();
var controlList = controllers.Select(controller =>
new
{
Actions = GetActions(controller),
Name = controller.Name,
}).ToList();
방법 GetActions
다음과 같이
공급자를 살펴 봤는데 좀 더 살펴볼 필요가 있지만 xml을 통해 메뉴를 정의해야하는 것처럼 보입니까? –
예, XML을 사용하여 메뉴를 정의해야합니다. 그러나 내가 제공 한 코드를 사용하여 초기 목록을 얻을 수 있습니다. 그래도 어떤 작업이 어떤 작업에 액세스 할 수 있는지 정의해야합니다. – amhed
사용자가 정의 할 수있는 권한 기반 사용자 권한이 있습니다. 멀티 테넌트 시스템이므로 테이블 기반 또는 협약 기반이어야합니다. 우리는 후자가 작동하도록 노력하고 있습니다. –