I have an ASP.NET MVC4 application in which I am creating multiple areas, is there a way I can find out programmatically the number of areas that are present and their names.
相关问题
- How do I create a multidimensional array of object
- How to create anchor href using Html.Helper [dupli
- Save Image to file keeping aspect ratio in a WPF a
- How to detect Carriage return in a string
- Value cannot be null or empty.\r\nParameter name:
相关文章
- MVC CDN fallback for Style Bundle
- Add to htmlAttributes for custom ActionLink helper
- Disable action method from being called from the a
- User.Identity.IsAuthenticated vs WebSecurity.IsAut
- Is there a way to update asp.net mvc bundle conten
- Can the “dynamic” type vary safely in a generic co
- MVC4 - ContextDependentView - What does it mean?
- How to pretty-print JSON script in MVC 4 API
AreaRegistration.RegisterAllAreas()
cannot be used pre-initialization of the web application. However, if you want to get the areas without callingRegisterAllAreas()
, e.g. in an automated test, then the following code may be helpful:Note that
MvcApplication
is the class derived fromHttpApplication
. You can use any class name as long as that class is in the same assembly as the assembly registrations, i.e. the classes derived fromAreaRegistration
. If you have split up your application with areas in more than one assembly, then you'd need to adapt this code accordingly so it searches all those assemblies.The
AreaRegistration.RegisterAllAreas();
registers each area route with theDataTokens["area"]
where the value is the name of the area.So you can get the registered area names from the
RouteTable
If you are looking for the
AreaRegistration
themselves you can use reflection to get types which derives fromAreaRegistration
in your assambly.