Thursday, June 9, 2016

Sitecore LinkManager.GetItemUrl duplicating the host name

I noticed an interesting feature of the LinkManager.GetItemUrl method (used in a custom module) in Sitecore where it was rerunning URLs with the host name twice. For example http://mysite.com

This was occurring because the module had UrlOptions with AlwaysIncludeServerUrl set to false and would assume that the link returned from LinkManager.GetItemUrl would never return the server URL.

However when the site definition (in Sitecore.config) has the targetHostName attribute set, the LinkManger will always return the server URL (from that setting). Which meant I had to update the module to handle this exception.

No comments:

Post a Comment