On my local standalone instance, I have a case where I am expecting an absolute URL for a media library item. However, in preview mode, the returned URL is never absolute:

MediaUrlBuilderOptions options = new MediaUrlBuilderOptions()
    AlwaysIncludeServerUrl = true,
    AbsolutePath = true

string url = HashingUtils.ProtectAssetUrl(MediaManager.GetMediaUrl(mediaItem, options));

// preview mode returns /-/media/images/my-image.jpg

// normal mode returns https://mysite.sc/-/media/images/my-image.jpg

My site config is:

<site name="website" set:targetHostName="mysite.sc" set:hostName="mysite.sc" />

This happens whether or not I have hostName set.

Is this expected behavior?

1 Answer 1


Yes link resolver behaves in this way, in preview mode If the Rendering.SiteResolving setting is true, and the dynamic link manager can determine a logical Web site for the linked item, and that site is not the context site, and the targetHostName attribute of that site has a value, then link manager uses the targetHostName attribute. If the targetHostName attribute has no value, and the hostName attribute has a value, then the link manager uses the hostName attribute.

Here is the url https://doc.sitecore.com/xp/en/SdnArchive/Articles/Administration/Configuring%20Multiple%20Sites/Adding%20New%20Site/site%20Attribute%20Properties/targetHostName.html for your reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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