Wednesday, December 7, 2011

Sitecore Context Item is not the expected item

Few days ago, I encountered a puzzling problem where the Sitecore Context Item is returning an Item from different webroot of another languge.

So for example,

Sitecore
* Content
** English
*** Item one
** China
*** Item one

When I am on Sitecore/Content/China/Item one, I would expect Sitecore Context Item to return Sitecore/Content/China/Item one. However strangely, it was returning Sitecore/Content/English/Item one.

The first thing I look was HttpRequestPipelines to see if any custom code cause this problem. However none of it, is the problem.

One of my colleague found the issue, it was to do with an Alias that was setup. Normally this will not cause a problem, because normally when we create an Alias we will use a different name from the item name.

Unfortunately the scenario that I faced previously was; Alias to the item with the item name itself.

i.e. (Alias) : Item One -> Sitecore/Content/English/Item one

This is the cause of the problem, because by default Sitecore Alias did not take into account Language variant and it shares Alias across the Site.

This means, when you type in http://mydomain.com/cn/item one, it will show content that is found on http://mydomain.com/en/item one.