Using cross site links.. aka dynamic links (part 1)

When you have multiple sites defined in Sitecore and you use LinkManager to get the URL to items in your site, all is well. Trouble arises however when you want a link to an item outside of the context site. For example, if you have a sitecore content tree and site config like:

  • /sitecore/content/Home
    • SiteA
      • ItemA1
    • SiteB
      • ItemB1

If you had a custom control on SiteA that used LinkManager.GetItemURL(ItemB1), the return URL would be something like:

when what you really want is:

Several people in my group searched high and low for a Sitecore configuration that would result in exactly that. After much research, it seemed that the undocumented “SiteResolving” setting is what we needed.

To get SiteResolving to work, you need to:

  1. Set the targetHostName on the desired site config entries
  2. When calling LinkManager.GetItemUrl, pass in UrlOptions with UrlOptions.SiteResolving=true.

It seems that if targetHostName is set and UrlOptions.SiteResolving=true, then when a GetItemUrl request is made to the LinkProvider it will check whether the requested item is a descendant of the context site. If not, then the SiteResolving logic kicks in. This logic takes the requested item path and recursively chops off the last part of the path until a match is found. The match is against the site config’s RootPath+StartItem. If a match is found, that site’s targetHostName is used when generating the URL.

However, the trickiness is really setting UrlOptions.SiteResolving to true, unless you are going to remember to explicitly set this each time you call LinkManager.GetItemUrl. You would think adding the following web.config setting would do the trick:

<setting name=”Rendering.SiteResolving” value=”true” />

But the neither the LinkProvider code nor the default UrlOptions seem to use this. So, in order to get this to work, I just added the following code to my custom LinkProvider:

public class LinkProvider : Sitecore.Links.LinkProvider


public override string GetItemUrl(Item item, UrlOptions options)


string itemUrl;

//other code

options.SiteResolving = Sitecore.Configuration.Settings.Rendering.SiteResolving;

itemUrl = base.GetItemUrl(item, options);

//other code

return itemUrl;




Thanks to Mike Casey for helping find this solution.

About Paul Martin

I enjoy rock climbing, playing guitar, writing code...
This entry was posted in Dynamic Links, LinkManager. Bookmark the permalink.

6 Responses to Using cross site links.. aka dynamic links (part 1)

  1. Pingback: Sitecore links in multisite solutions – SiteResolving « Brian Pedersen’s Sitecore and .NET Blog

  2. Pingback: Sitecore Links with LinkManager and MediaManager | Brian Pedersen's Sitecore and .NET Blog

  3. Pingback: Sitecore Links with LinkManager and MediaManager | CMS News Today

  4. GFoley83 says:

    Very helpful. Thanks!

  5. Pingback: Cross-site linking in Sitecore | True Clarity Developer Blog

  6. Nice article. It’s also possible to simplify link generation with site resolution by front-ending the Sitecore API:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s