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>