ASP.NET MVC 以编程方式获取控制器列表 [英] ASP.NET MVC Programmatically Get a List of Controllers
本文介绍了ASP.NET MVC 以编程方式获取控制器列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 ASP.NET MVC 中有没有办法通过代码枚举控制器并获取它们的名称?
In ASP.NET MVC is there a way to enumerate the controllers through code and get their name?
示例:
AccountController
HomeController
PersonController
会给我一个列表,例如:
would give me a list such as:
Account, Home, Person
推荐答案
您可以通过程序集进行反思,并找到所有继承自 System.Web.MVC.Controller 类型的类.下面是一些示例代码,展示了如何做到这一点:
You can reflect through your assembly and find all classes which inherit from type System.Web.MVC.Controller. Here's some sample code that shows how you could do that:
http://mvcsitemap.codeplex.com/WorkItem/View.aspx?WorkItemId=1567
这篇关于ASP.NET MVC 以编程方式获取控制器列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文