asp.net mvc 获取项目中所有 controller 和 action

通过筛选程序集中的类型得到:

        public ActionResult Index()
        {
            var controllers =
                from t in GetAllTypes()
                where typeof(Controller).IsAssignableFrom(t) && !t.IsAbstract
                orderby t.FullName
                from m in t.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                where !m.IsSpecialName
                select new { ControllerName = t.FullName, ActionName = m.Name, Params = m.GetParameters() };

            controllers.ToList().ForEach(c =>
            {
                Response.Write(string.Format("Controller: {0} , Action: {1}({2}) <br/>", c.ControllerName, c.ActionName, string.Join(", ", c.Params.Select(p => p.Name).ToArray())));
            });
            Response.Write(string.Format("Controller / action count: {0}  <br/>", controllers.Count()));
            Response.Write(string.Format("Controller count: {0}  <br/>", controllers.GroupBy(c => c.ControllerName).Count()));

            return Content("");

        }

        private static Type[] GetAllTypes()
        {
            //return typeof(TestController).Assembly.GetTypes();

            var ts = new List<Type>();
            foreach (var item in AppDomain.CurrentDomain.GetAssemblies())
            {
                ts.AddRange(item.GetTypes());
            }
            return ts.ToArray();
        }

放到 一个action 中就可以输入了。