A while ago I released our first version of a module that is available on the Sitecore Marketplace to enable Sitecore to work with aliases in a multi-site environment.
The idea is that multiple websites can use the same alias names.
http://site1/alias1 -> points to item ‘/sitecore/content/site1/item/itemlvl2/item’
http://site2/alias1 -> points to item ‘/sitecore/content/site2/item/itemlvl2/item’
http://site3/alias1 -> points to item ‘/sitecore/content/site3/item/itemlvl2/item’
Sitecore out of the box supports only having a single aliasname across your complete environment. I have recently implemented this solution for one of our customers and extended the functionality to completely disable the standard Sitecore aliasresolver (so it doesn’t even call the base.Process method anymore). I also wrote a simple layout that you can add in your solution to convert any existing alias items so that they will work in the new multi-site strategy.
What the script does:
- Creates alias folders under all of the website’s (from the sitedefinitions)
- Checks all existing alias items and copies them to the newly created alias folders (based on the Target Item of the alias item). This required some logic to determine the root site for an item, but this has been built in aswell.
From then on the custom AliasResolver – that is patched from a config file which is placed in the /app_config/include folder – will resolve the items from the alias folder directly under the website instead of the System/Alias folder Sitecore normally uses.
I upgraded one of our Sitecore solutions from Sitecore 6.2 (rev. 100507) to Sitecore 8.1 (rev. 151207). After the upgrade we noticed that the display of time on the website was slightly off. Instead of showing the GMT + 1 time it showed the UTC time (which is 2 hours off in our case). This caused that all newly created items (wheter it be reactions on news or news items itself) showed the wrong time. An item created on 11-04-2016 – 11:04 would be shown as 11-04-2016 – 09:04. As you might guess this wasn’t really what our customer was looking for and I haven’t stumpled upon any tips regarding this issue in the upgrade guide while upgrading the solution.
Now I have decompiled the Sitecore.Kernel and read some other posts regarding this issue I would like to share my solution to this problem. As per Sitecore documentation provided in the Sitecore.config file I looked for the Timezone I would like to use on msdn:
MSDN Article – Timezones
In my case I chose to use the “W. Europe Standard Time” so my settting in the sitecore.config file looked like this:
<!-- SERVER TIME ZONE
This setting specifies the server time zone that is used by the server to convert UTC time to local time, for example "GMT Standard Time".
The value must be parsable to a valid Time Zone ID. See http://msdn.microsoft.com/en-us/library/gg154758.aspx
If blank, Sitecore uses the operating system time zone.
Default value: "" (use the operating system time zone)
<setting name="ServerTimeZone" value="W. Europe Standard Time" />
Now this seems all nice and ready to roll, but you aren’t done yet. If you are using for example “Sitecore.Statistics.Created” as your DateTime object and just format this date and .toString() it in any format with a time specification you will not yet see the correct time displayed. I therefor used the Sitecore.DateUtil.ToServerTime() method, which uses the ServerTimeZone setting we just specified to convert between the UTC and server time.
DateTime serverTime = Sitecore.DateUtil.ToServerTime(item.Statistics.Created);
string dateCreated = serverTime.ToString("dd-MM-yyyy, HH:mm");
This results in the right date / time being shown on your website.
Hope you will find this article useful!