Sitecore links in multisite solutions – SiteResolving

One of the key features in Sitecore is that you can have multiple sites in the same installation. This is not just about saving money on licenses. The feature allows you to, for example, operate one main website and a multitude of subsites each having their own URL. Because they share the same Sitecore, you can share resources like the media library or templates, layouts, users etc.

Another key benefit is that it allows you to create internal links between sites. These links are maintained by the LinkManager so links are updated automatically. And when they are rendered they will still point to the correct host.

Imagine this simplified scenario where you have 2 websites called SITE1 and SITE2. In Sitecore you create the 2 websites:

/sitecore/

/content/

/site1/

/home/

/subitems…

/site2/

/home/

/subitems…

To give each website its own hostname you need to set up 2 new sites in the web.config:

<site name="website_1" hostName="www.site1.com" language="en" cacheHtml="false" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content/site1" startItem="/home" database="web" domain="extranet" allowDebug="true" htmlCacheSize="10MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" />
<site name="website_2" hostName="www.site2.com" language="en" cacheHtml="false" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content/site2" startItem="/home" database="web" domain="extranet" allowDebug="true" htmlCacheSize="10MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" />

Now when accessing www.site1.com you are given the home page at /sitecore/content/site1/home, and www.site2.com returns the home page at /sitecore/content/site2/home.

Imagine you create a link on the page at /site1/home/subitem to /site2/home/subitem. Internally in Sitecore this is stored as a GUID. But when rendered, the LinkManager ensures that the link is rendered as www.site2.com/subitem.aspx.

It does so because in the web.config, SiteResolving is enabled by default:

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

When SiteResolving is true, the LinkManager will resolve the correct site from the <sites> section in web.config. It makes a best match and finds the site that the page belongs to, and resolves the hostname and URL based on the context of the site it found.

If you disable the SiteResoving the LinkManager stays in the current context. The link would then have been www.site1.com/sitecore/content/site2/home/subitem.aspx.

LIMITATIONS IN THE SITERESOLVER

UPDATE: Please note that these limitations have been adressed from Sitecore 6.4.1 Update 6. Read more about it here.

There are limitations to siteresolving. Imagine you have a setup where you not only have multiple sites, but also multiple languages per site. And that each of the languages have their own host.

So if your SITE1 has 2 languages (english and danish) you have www.site1.com and www.site1.dk. And SITE2 also has 2 languages, www.site2.com and www.site2.dk.

If you enable SiteResolving, all links linking to the same website (all links from SITE1 to SITE2) will be resolved as links to the first site content found in the web.config.

What does this mean? It means that if you in the web.config have the following order of sites:

All links from www.site1.dk will point to www.site1.com/dk/subitem.aspx. The SiteResolver does this because the algorithm resolves URLS as the first path that is the shortest is the one used. And since www.site1.com/dk/subitem.aspx has just as short a path as www.site1.dk/dk/subitem.aspx it’s a match, and voila, problem solved.

MORE READING

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in Sitecore 6 and tagged , , , . Bookmark the permalink.

6 Responses to Sitecore links in multisite solutions – SiteResolving

  1. I was actually just looking at this, and was surprised to discover that Rendering.SiteResolving is in fact *not* used by the LinkManager. If you trace it in Reflector, you’ll see it’s used in the RenderField pipeline, and in an XslHelper, which may cause many links to be expanded. But a direct API call to LinkManager.GetItemUrl (such as you might use in a Sublayout) will not use this setting. You need to explicitly set it in the UrlOptions and pass in those options to GetItemUrl. It also appears that there’s no built-in way of configuring this in the default UrlOptions configured on the LinkProvider?

    Have you experienced otherwise?

  2. briancaos says:

    The GetItemUrl uses the DefaultUrlOptions which is a global set of UrlOptions, and I guess you are right that these DefaultUrlOptions does NOT read from the Rendering.SiteResolving settings. Instead it’s false by default.
    It’s only the RenderDocx and RenderField pipelines and the XSL extensions that sets the “SiteResolving” property based on the web.config settings.

    You can see a solution to this problem in this blog: http://sitecorepm.wordpress.com/2010/08/04/using-cross-site-links-dynamic-links/
    Another solution is to overwrite the default URL options, like this:

    Sitecore.Links.LinkManager.GetDefaultUrlOptions().SiteResolving = true;

  3. Pingback: Sitecore cross-site and cross-language links resolved in 6.4.1 release 120113 « Brian Pedersen’s Sitecore and .NET Blog

  4. Alexey Romaniuha says:

    >> Imagine you have a setup where you not only have multiple sites, but also multiple languages per site.

    To that point, you might also want to check two new settings introduced in 6.4.1 Update-6:

    Rendering.SiteResolvingMatchCurrentSite
    Rendering.SiteResolvingMatchCurrentLanguage

    They are designed to allow more agility when configuring site resolving logic, specifically in regards to multilingual configurations. More information about these settings can be found in the CMS release notes:
    http://sdn.sitecore.net/Products/Sitecore%20V5/Sitecore%20CMS%206/ReleaseNotes/ChangeLog.aspx

  5. Pingback: Sitecore: Sharing Content over Multiple Sites | Ruben's Happy Coding Paradise

  6. Great post and comments. It should be possible to wrap up all of this using extension methods too: https://digitalrumpus.wordpress.com/2015/06/15/easily-construct-site-resolving-urls-in-sitecore-using-extension-methods/

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s