2013-01-02 34 views
1

在MVC路由中,我遇到了问题。MVC 4区域寄存器排序

在基本路由中,您可以按照自己的意愿简单地对路由进行排序。如下所示:

 routes.MapRoute(
      "Default", 
      "{controller}/{action}/{id}", 
      new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
      new [] {"SampleApp.UI.Web.Controllers"} 
     ); 

     routes.MapRoute(
      "CompanyRoute", 
      "{Company_url}/{action}/{id}", 
      new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
      new[] { "SampleApp.UI.Web.Controllers" } 
     ); 

那些地区呢?

在特殊情况下,我需要在其他区域之前注册一个区域。 如何对区域路线进行排序?

回答

0

从我想通了与反汇编的帮助:

internal static void RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, object state) { 
    List<Type> areaRegistrationTypes = TypeCacheUtil.GetFilteredTypesFromAssemblies(_typeCacheName, IsAreaRegistrationType, buildManager); 
    foreach (Type areaRegistrationType in areaRegistrationTypes) { 
     AreaRegistration registration = (AreaRegistration)Activator.CreateInstance(areaRegistrationType); 
     registration.CreateContextAndRegister(routes, state); 
    } 
} 

这是一个抽象类AreaRegistration您所有的自定义区域的注册类被称为的方法。正如你所看到的,没有订购。更深入的TypeCacheUtil.GetFilteredTypesFromAssemblies方法没有排序。

我看不到任何方式使用AreaRegistration类进行可订购区域注册。该班级没有任何可用于此目的的扩展点。