SaaS CMS has officially launched! Learn more now.

Example of moving simple address router to be the last router, without upgrading the CMS?

Vote:
 

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?

#204405
May 31, 2019 8:43
Vote:
 

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"
                    });

            
            
        }
#204407
May 31, 2019 10:11
Vote:
 

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.

#204411
May 31, 2019 11:07
Vote:
 

Ok, so there's no working example of moving the router?

#204450
Jun 03, 2019 8:09
Vote:
 

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

#204452
Jun 03, 2019 9:39
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.