2
votes

I have created three sites in Sitecore(in same instance). Now I have to provide the cross site links of other two sites on the current site. How it can be done through code. (Not using the hard coded path )

2
Have you tried to add targetHostName to every site definition (e.g. <site name="custom" patch:before="site[@name='website']" targetHostName="www.custom.com") and then just select item from the other site?Marek Musielak
<setting name="Rendering.SiteResolving" value="true" /> Can you check if this value is true?Vlad Iobagiu

2 Answers

0
votes

You need to have two sites defined into site definition, you will have something like:

 <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:

1 When SiteResolving is true, the LinkManager will resolve the correct site from the 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.

You can find more information on below links:

https://briancaos.wordpress.com/2012/03/28/sitecore-links-in-multisite-solutions-siteresolving/ https://www.sitecore.net/de-de/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2013/10/sitecore-multisite-part-4-cross-site-links.aspx http://www.nonlinearcreations.com/Digital/how-we-think/articles/2014/11/Sitecore-host-name-attribute-in-multi-sites.aspx

0
votes

Siteresolving needs to be on, and it will usually just work if you have one domain per site. Sometimes it can also depend on how your content trees look and the order of your site definitions in web.config.

More info and worse case nested scenarios explained here: http://blog.paulgeorge.co.uk/2011/05/01/sitecore-linkmanager-inside-out-muti-site-and-sub-site-setups/