4

I have an issue with mapping SitecoreInfoType.Url on a sitecore multisite solution.

I have in sitecore 2 websites:

  • Site A
  • Site B

Site A contains some articles:

  • www.Site-A/Articles/Article 1
  • www.Site-A/Articles/Article 2

On our main "Article landing page", we have a widget that shows a short description of each article with links to article page.

for using the url, we are mapping it with SitecoreInfoType.Url

e.g.

    [SitecoreInfo(SitecoreInfoType.Url)]
    public virtual string Url { get; set; }

This is rendered correctly as it is used on Site A, we get dynamic urls like /en/Articles/{Article Name}.

If we try to use the widget on Site B, the url is not generated as expected:

  • /en/sitecore/content/Site A/Home/Articles/{Article Name}

We already have implemented on website Sitecore fields of Link type and we are using UrlOptions for solving this kind of behaviour.

e.g.

    [SitecoreField(UrlOptions = SitecoreInfoUrlOptions.SiteResolving)]
    public virtual Link AlternateLink { get; set; }

This will generate the expected result. If we are trying to generate a Link for a target item that is under other website, domain will be used for generating url.

  • Target item is under Site A.
  • Widget is used on Site B and context is set to Site B
  • Link Url is generated like: www.Site-A/Articles/{Target item}

Unfortunately glass mapper is not mapping in the same way SitecoreField and SitecoreInfoType.Url.

Update on code:

    [SitecoreInfo(SitecoreInfoType.Url, UrlOptions = SitecoreInfoUrlOptions.SiteResolving)]
    public virtual string Url { get; set; }

And in similar context:

  • Target item is under Site A.
  • Widget is used on Site B and context is set to Site B
  • Link Url is generated like: /en/sitecore/content/Site A/Home/Articles/{Target item}

Note:

  • Other UrlOptions used on SitecoreInfoType.Url are working:

SitecoreInfoUrlOptions.AddAspxExtension

SitecoreInfoUrlOptions.AlwaysIncludeServerUrl

SitecoreInfoUrlOptions.LanguageEmbeddingNever

In case of using SitecoreInfoUrlOptions.AlwaysIncludeServerUrl the result is strange: www.Site B/en/sitecore/content/Site A/Home/Articles/{Target item}

For me it seems that this is a bug in glass mapper library.

Anyone had this issue and a fix or workaround? I would prefer to not use Sitecore API and try to get the item and use LinkManager again as this is already used in glass mapper implementation.

Here is my site definition config:

<sites>
    <site name="siteA"
       patch:before="site[@name='website']"
       hostName="siteA.domain.com"
       targetHostName="siteA.domain.com"
       virtualFolder="/"
       physicalFolder="/"
       rootPath="/sitecore/content/domain/siteA"
       startItem="/Home"
       database="web"
       domain="extranet"
       allowDebug="true"
       cacheHtml="true"
       htmlCacheSize="50MB"
       enablePreview="true"
       enableWebEdit="true"
       enableDebugger="true"
       disableClientData="false"
       scheme="http"
       />
  <site name="siteB"
        patch:before="site[@name='website']"
        hostName="siteB.domain.com"
        targetHostName="siteB.domain.com"
        virtualFolder="/"
        physicalFolder="/"
        rootPath="/sitecore/content/domain/siteB"
        startItem="/Home"
        database="web"
        domain="extranet"
        allowDebug="true"
        cacheHtml="true"
        htmlCacheSize="50MB"
        enablePreview="true"
        enableWebEdit="true"
        enableDebugger="true"
        disableClientData="false"
        scheme="http"
        />
</sites>
Community
  • 1
  • 1
Sandor
  • 51
  • 3
  • can you try [SitecoreField(UrlOptions = SitecoreInfoUrlOptions.AlwaysIncludeServerUrl | SitecoreInfoUrlOptions.SiteResolving)] public virtual Link MyLink{get;set;} ? – Vlad Iobagiu Jan 17 '17 at 12:25
  • Mentioned UrlOptions set on SitecoreField are working well. The problem is with SitecoreInfoType.Url and this one as described is not working: public virtual string Url { get; set; } Note that is of type string, not Link. Thanks, Sandor. – Sandor Jan 17 '17 at 12:37
  • Chcck that the setting `Rendering.SiteResolving` is set to `true` in the Sitecore check of your config. Glass should then use that value correctly. – jammykam Jan 17 '17 at 22:24
  • The SiteResolving is set to true as default and I re-checked. In my example, I'm trying to add custom UrlOption, and in this case, the default configurations should not be used. – Sandor Jan 18 '17 at 09:48
  • OK, I found the issue. It is about how the routing of the sitecore website is done and how the site resolver works. The site resolver uses two things from site definition, root path and start item. I was trying to resolve url of items that where under root, not under root path + home item. E.g. sitecore/content/Site A/{folder}/{ArticleName}. The correct path where items should be placed would be: sitecore/content/Sita A/Home/{folder}/{ArticleName}. – Sandor Jan 18 '17 at 12:48

0 Answers0