2013-01-02 83 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類進行可訂購區域註冊。該班級沒有任何可用於此目的的擴展點。