Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 16, 2011 08:46 AM by ignatandrei
Member
4 Points
3 Posts
Jan 15, 2011 10:23 PM|LINK
MVC3 RegisterAllAreas() scan assemly for AreaRegistration and register routes.
No way to specify area routes order. But this order critical important to select right controler.
In most cases you have small set of areas and no hard work to manualy register its.
Here is small helpfull code to easy register areas with right ordering.
public static class Utils { public static void RegisterArea<T>(RouteCollection routes, object state) where T : AreaRegistration { AreaRegistration registration = (AreaRegistration)Activator.CreateInstance(typeof(T)); AreaRegistrationContext context = new AreaRegistrationContext(registration.AreaName, routes, state); string tNamespace = registration.GetType().Namespace; if (tNamespace != null) { context.Namespaces.Add(tNamespace + ".*"); } registration.RegisterArea(context); } }
Now you can replace in Application_Start:
Utils.RegisterArea<SystemAreaRegistration>(RouteTable.Routes, null); Utils.RegisterArea<ClientSitesAreaRegistration>(RouteTable.Routes, null); // don't register automaticaly now -- AreaRegistration.RegisterAllAreas();
"ASP.NET MVC" "MVC" "Tips"
All-Star
137716 Points
22159 Posts
Moderator
MVP
Jan 16, 2011 08:46 AM|LINK
please format your code.
Kuvalda.Spb....
Member
4 Points
3 Posts
Tips: Area registration order (here solution)
Jan 15, 2011 10:23 PM|LINK
MVC3 RegisterAllAreas() scan assemly for AreaRegistration and register routes.
No way to specify area routes order. But this order critical important to select right controler.
In most cases you have small set of areas and no hard work to manualy register its.
Here is small helpfull code to easy register areas with right ordering.
public static class Utils { public static void RegisterArea<T>(RouteCollection routes, object state) where T : AreaRegistration { AreaRegistration registration = (AreaRegistration)Activator.CreateInstance(typeof(T)); AreaRegistrationContext context = new AreaRegistrationContext(registration.AreaName, routes, state); string tNamespace = registration.GetType().Namespace; if (tNamespace != null) { context.Namespaces.Add(tNamespace + ".*"); } registration.RegisterArea(context); } }Now you can replace in Application_Start:
"ASP.NET MVC" "MVC" "Tips"
ignatandrei
All-Star
137716 Points
22159 Posts
Moderator
MVP
Re: Tips: Area registration order (here solution)
Jan 16, 2011 08:46 AM|LINK
please format your code.