views:

58

answers:

1

Since this stuff is fair new I couldn't figure out any good reference on it.

I want to use reflection to enumerate through all the controller in my application. This is not hard using reflection. But since area come into place. How do I know which area (if any) does a particular controller belong to?

Maybe I am doing it wrong, maybe I need to enumerate through the area instead... so then how do I do that? What if a controller doesn't belong to any area? Is there a default one?

There are many good write up out there that explain in depth about the controller and view. If somebody can point me to something similar for area I would greatly appreciate it.

+1  A: 

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%28VS.100%29.aspx

Sounds tricky, good luck!

jfar
I've thought of this two approach before though neither seem elegant enough hence I posted the question here. Using the namespace is nice, convention over configuration kinda thing, but it's rather fragile.Using the RouteTable might work but it seem a little hackish to me. Either way I will play around with it some more and report back :)
firefly