You could do something like this I guess
private void PutSimpleAddressLast(RouteCollection routes)
{
// Find index of default route
int index = -1;
for (int i = 0; i < routes.Count; i++)
{
if (!(routes[i] is IContentRoute contentRoute) || !contentRoute.Name.Equals(RoutingConstants.SimpleAddressKey))
{
continue;
}
index = i;
break;
}
// remove default route
routes.RemoveAt(index);
// new route is registered last
routes.MapSimpleAddressRoute(
RoutingConstants.SimpleAddressKey,
"{simpleaddresslanguage}/{simpleaddress}/{partial}/{action}",
new
{
action = "index"
});
}
I tried what Jeoren did (mine is a bit different), based on this https://vimvq1987.com/episerver-cms-performance-optimization-part-1/
private void Global_RoutesRegistered(object sender, RouteRegistrationEventArgs e)
{
var simpleAddressRouter =
e.Routes.OfType<IContentRoute>().FirstOrDefault(r => r.Name.Equals("simpleaddress"));
if (simpleAddressRouter != null)
{
e.Routes.Remove((RouteBase) simpleAddressRouter);
e.Routes.MapSimpleAddressRoute(
name: RoutingConstants.SimpleAddressKey,
url: "{simpleaddresslanguage}/{simpleaddress}/{partial}/{action}",
defaults: new { action = "index" });
}
}
However, can confirm it does not work for me.
The code sample I gave worked in CMS 11 to move the simple address router back to the beginning, those lines I omitted from the sample though
Hi!
Does anyone have example code of how to move the simple address router to be the last registered router, without upgrading the CMS to version 11?