Episerver and Page Languages

We’ve been doing some work recently using EpiServer, extending it to fit our needs, to support our new website look which is one of many new features coming soon. Having website content in more than one language reflects the international coverage that Esendex has.

We ran into a bug today which initially wasn’t easy to spot where adding a Page Language to an existing page was causing EpiServer to hang as it entered an endless loop of calls to a stored procedure called ‘netPropertySearchStringMeta’.

We were advised to try using a trial copy of dotTrace Profile to see what was happening as we created this new French page which just hung the browser when we clicked save. After a quick install, and the profiler attaching itself to IIS as I ran the Web project in Debug mode, a snapshot was captured.

dotTrace Snapshot

As the screenshot above shows, one call to EpiServer.Global.CreatePageURLSegment was creating 678 calls which then eventually called the stored procedure 1,356 times. This was only during the 19 seconds that I was running the snapshot for. The first time we noticed this issue, it had been running for over a million times before we caught it in the act.

Ian showed me Reflector and we had a look into the CreatePageURLSegment method in the Episerver dll. Even though Reflection can’t resolve private variable names or methods, we spotted a while loop at the end of the CreatePageURLSegment method which appeared to be the offender.

It appears to check if the name of the page to be created exists already and returns a translated error string if something is found. The while loop keeps on going until the function returns an empty string. This myth of an empty string being returned is sadly lacking when the checking function keeps on returning an error string.
The while loop tries its best to add one to the name of the page to be created in an effort to give you the result you’re after, but again the checking function spits it back.

Why? Well EpiServer’s handling of localisation is to prefix the URL with the language codes specified: en, fr, de, es etc. So when creating a French page, it tries to see if /fr/page_parent/page_name is free, for example.

All is well until you introduce some existing content directories into your Episerver root directory. Yes, the culprit of our trouble was the fact we had an existing /fr/ directory. Any attempts of adding 1 to the page name was never going to help Episerver save this new page, and so it locked itself into an endless, futile attempt.

The solution was to go into the Admin Mode and add a new French language code of FRA for EpiServer to use with the FR-fr language code and renamed the old one ‘Old Francais’. Then all I had to do was swap the Language Settings so that the new Francais was available for pages to use.

And, voila!

Like most development problems, if you install something on a fresh server in exactly the method described, you’ll never have a problem. Real world development and implementation is rarely so simple, hence the driving force behind many blogs. Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.