0

Let have example structure:

enter image description here

Normally when there is no SXA tenants exist and New Sample Item is published, LinkBuilder.GetItemUrl() will return something like

https://sc93sc.dev.local/en/New-tenant/New-site/Home/New-Sample-Item.

The problem is when SXA tenants are there. Then link should be created referring to it.

In short, I'm getting URL something like above which returns 404 when I try to use it. To make it work link has to be https://sc93sc.dev.local/en/New-Sample-Item, so relative to tenant root, not Sitecore root.

Is there a way to get that without custom LinkProvider?

Code:

var siteName = "website";
var site = SiteContext.GetSite(siteName);
var options = new UrlOptions
            {
                AlwaysIncludeServerUrl = true,
                Site = GetSiteForPreviewLink(),
                Language = Language.Parse(language.Name)
            };

var builder = new LinkProvider.LinkBuilder(options);
link = builder.GetItemUrl(sitecoreItem);
  • Are you using LinkProvider for Item URL? if yes, did you try by using LinkManager.GetItemUrl instead of it? – Mahendra Shekhawat Mar 27 at 13:17
  • yes, and it giving the wrong result too "/sitecore/content/New-tenant/New-site/Home/New-Sample-Item". – sc guest Mar 27 at 13:36
  • Is sc93sc.dev.local added as a valid URL to the Site Grouping of New Site? – Richard Seal Mar 27 at 14:35
  • yes. It is an example of my local instance. Seems is is added by setting "AlwaysIncludeServerUrl = true" – sc guest Mar 27 at 14:54
  • What is the GetSiteForPreviewLink doing in your code? – Gatogordo Mar 27 at 16:04
0

Mistery solved. Kinda. To make sitecore root relative URLs work I needed to change value of Virtual Folder field in Settings of my "New site" from default "/" to some "/whatever". 🤷‍♂️

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.