在MVC路由中我遇到了问题。
在基本路由中,您只需按照您希望的顺序编写路线即可对其进行排序。如下所示:
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 :(得分: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
类进行可订购区域注册。该类没有任何可用于此目的的扩展点。