0

由于这些东西很新,我无法找到任何好的参考。

我想使用反射来枚举我的应用程序中的所有控制器。使用反射并不难。但自从面积到位。我如何知道特定控制器属于哪个区域(如果有)?

也许我做错了,也许我需要枚举该区域......那么我该怎么做呢?如果控制器不属于任何区域怎么办?有默认的吗?

有很多很好的文章深入解释了控制器和视图。如果有人可以为我指出类似的区域,我将不胜感激。

4

1 回答 1

1

You'll either have to change the namespace your controllers are in to detect the areas or grab the route data from ( RouteTable.Routes ) loop through it and try to match up the data tokens, aka what you put in {controller}, and/or the url information:

Here's how to get the route information:

 foreach (RouteBase routeBase in RouteTable.Routes)
 {
      Route route = routeBase as Route;

      var routeUrl = route.Url;                
 }

Phil Haacks Route Debugger may help you: http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

Good MSDN Article about Areas: http://msdn.microsoft.com/en-us/library/ee461420(VS.100).aspx

Sounds tricky, good luck!

于 2009-11-28T04:28:18.773 回答