Johan Björnfot
Sep 8, 2014
  10874
(8 votes)

Changes in simple address routing

In package EPiServer.CMS.Core.7.13.3 we have solved an issue that causes a slightly different behaviour in how simple addresses are routed. As a background: for “ordinary” content routing we introduced a more strict handling in 7.5 where for example it was not possible to have a language segment specifying one language while the segment it self was on a content instance on another language. Like for example:

http://mysite/en/produkter (where “produkter” is the segment on the swedish version)

In CMS 7 that was possible to route and resulted in the english version of the page. In CMS 7.5 that results in a 404. We also introduced a configuration setting strictLanguageRouting that can be set to false to get the more tolerant behaviour as in CMS 7.

Now we have also changed simple address routing so it is more strict. So given that a page exist in both language "en" and language "sv" and has simple addresses "ensimple" and "svsimple" the following scenarios apply. For those scenarios that differs from previous version a parenthesis is added describing the old behaviour:

No host language mapping, strictLanguageRouting=true

  1. http://sitehost/ensimple => english page

  2. http://sitehost/svsimple => swedish page

  3. http://sitehost/en/ensimple => english page

  4. http://sitehost/sv/svsimple => swedish page

  5. http://sitehost/sv/ensimple => 404 (this gave swedish page in previous version)

No host language mapping, strictLanguageRouting=false

  1. http://sitehost/ensimple => english page

  2. http://sitehost/svsimple => swedish page

  3. http://sitehost/en/ensimple => english page

  4. http://sitehost/sv/svsimple => swedish page

  5. http://sitehost/sv/ensimple => swedish page

Host "sitehost" mapped to language "en", strictLanguageRouting=true

  1. http://sitehost/ensimple => english page

  2. http://sitehost/svsimple => 404 (this gave english page in previous version)

  3. http://sitehost/en/ensimple => 404 (this gave english page in previous version)

  4. http://sitehost/sv/svsimple => swedish page

  5. http://sitehost/sv/ensimple => 404 (this gave swedish page in previous version)

Host "sitehost" mapped to language "en", strictLanguageRouting=false

  1. http://sitehost/ensimple => english page

  2. http://sitehost/svsimple => swedish page

  3. http://sitehost/en/ensimple => english page

  4. http://sitehost/sv/svsimple => swedish page

  5. http://sitehost/sv/ensimple => swedish page

To get the more tolerant behaviour as in previous versions you can either set the strictLanguageRouting attribute (on configuration element applicationSettings) to false. That will however not only affect simple address but also "ordinary" routing so it works as in EPiServer 7. To only affect simple address you could have an initialization module that configures simple address routing to not use strict language routing as the following code:

using EPiServer.Framework;
using EPiServer.Web.Routing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcPreview
{
    [InitializableModule]
    public class SimpleAddressModule : IInitializableModule
    {
        public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
        {
            EPiServer.Global.RoutesRegistered += delegate(object source, RouteRegistrationEventArgs args)
            {
                var simpleAddressRoute = args.Routes.OfType<ContentRoute>().FirstOrDefault(r => r.Name.Equals("simpleaddress"));
                if (simpleAddressRoute != null)
                {
                    simpleAddressRoute.StrictLanguageRoutingResolver = () => false;
                }
            };
        }

        public void Preload(string[] parameters)
        {
        }

        public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context)
        {
        }
    }
}
Sep 08, 2014

Comments

K Khan
K Khan Sep 9, 2014 12:56 PM

There are few routing issues for commerce have also been fixed in Commerce 7.11.0
e.g.
http://site.development.local/US/businesscategory
http://site.development.local/UK/businesscategory
was resulting an error but now its an OK to go. You can find details here
http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=88578&epslanguage=en

Martin Pickering
Martin Pickering Sep 9, 2014 01:54 PM

An interesting change. I believe that I understand this from an inbound routing viewpoint, but I am left wondering about effects in regard of outbound routing.

For example:

From your "No host language mapping, strictLanguageRouting=true" example above, which of the accepted routes would be published by the outbound url re-writing module? I am assuming that it would be:
1) http://sitehost/ensimple => english page
2) http://sitehost/svsimple => swedish page

Regardless of what the standard/default behaviour actually is, are there ways to configure or otherwise influence the outbound url re-writer to behave differently, i.e. publish the alternative acceptable form instead:
1) http://sitehost/en/ensimple => english page
2) http://sitehost/sv/svsimple => swedish page

Might you be able to offer some insight please? Thanks

Sep 10, 2014 09:11 AM

Regarding outgoing routing. For CMS simple address is not taken into consideration during link generation. Instead will content gets it outgoing link from "ordinary" content route. That is it will get a route that follows the structure like
http://sitehost/en/toplevel/sublevel/leaf

Antti Alasvuo
Antti Alasvuo Nov 3, 2017 11:39 AM

Old post but what about nowdays (version 10.x =>)? The ContentRoute is depracated and cannot be used.

Similiar implementation can be achieved by using Episerver internal DefaultContentRoute class like this:

EPiServer.Global.RoutesRegistered += delegate (object source, RouteRegistrationEventArgs args)
 {
                // NOTICE: Using Episerver internal implementation of DefaultContentRoute that can change
                var simpleAddrRoute = args.Routes.OfType().FirstOrDefault(cr => string.Compare(cr.Name, "simpleaddress", StringComparison.OrdinalIgnoreCase) == 0) as DefaultContentRoute;

                if (simpleAddrRoute != null)
                {
                    simpleAddrRoute.StrictLanguageRoutingResolver = () => false;
                }
};

Or should we only use the "strictLanguageRouting" setting in configuration file?

Please login to comment.
Latest blogs
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024