U4-9956 - UrlWithDomain Does Not Work for Media Items

Created by Simon Dingley 26 May 2017, 09:39:33 Updated by Alessandro Calzavara 26 May 2017, 13:15:38

Is duplicated by: U4-9955

Take the following to try and produce absolute urls to an image.

var siteLogo = homepage.GetPropertyValue("siteLogo");

if (siteLogo != null) { Logo }

This results in an exception AbsoluteUrl is not supported for media types.

Since you can call UrlWithDomain() on a media item, if there is enough context to form an absolute url, can we not do so? E.g. if it is rendered in the context of a piece of content.


Søren Gregersen 26 May 2017, 10:17:27

This could provide a solution.

    public static string UrlWithDomain(this IPublishedContent media, IPublishedContent content)
        var contentUrl = new Uri(content.UrlWithDomain());
        var url = new Uri(contentUrl, new Uri(media.Url, UriKind.Relative));
        return url.AbsoluteUri;

Some caveats Media is stored a IPublishedContent, so a new method should have a new name, in order to not confuse the users of any method(s). The method-signature could be "UrlForMedia(this IPublishedContent media, IPublishedContent content)" or "MediaAbsoluteUrl(this IPublishedContent media, IPublishedContent content)".

The "content" could be picked up from "CurrentPage". I would advise against this, since it makes it a bit "magical" as to where the value would then stem from. Having it as a (required) parameter, would let the developer be in charge of this.

Priority: Normal

Type: Bug

State: Submitted


Difficulty: Normal

Category: Architecture

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.5.11

Due in version:


Story Points: