More in this section
Forums / Developing with Sitefinity / MediaUrl vs ItemDefaultUrl

MediaUrl vs ItemDefaultUrl

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Dan
    Dan avatar
    2 posts
    01 Aug 2014
    21 Sep 2015
    Link to this post
    I have a custom widget that shows a collection of images in a slideshow. Each image is a property of a Dynamic Content Type object returning a Telerik.Sitefinity.Libraries.Model.Image object, from which I get the MediaUrl property. This property returns a value like "http://localhost:60876/images/default-source/Heros/slide1.jpg?sfvrsn=2".

    The problem is that the URL is fully specified, includeing the protocol, instead of a root relative URL (e.g. /images/default-source/Heros/slide1.jpg?sfvrsn=2).

    Our production servers are load balanced by an F5 device, which also hosts the SSL certificate, so the actual servers don't know that the site is using HTTPS instead of HTTP. This means the image's MediaUrl property returns a value like "". But this is the wrong URL (http instead of https) so the browser shows an insecure connection to the server because of the mixed content.

    I could use the image's ItemDefaultUrl property, which is root relative but doesn't include the cache busting sfvrsn query string property (ex /images/default-source/Heros/slide1).

    Is there a way to get an image's root relative Url with the sfvrsn query string parameter?


  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    17 Aug 2017
    24 Sep 2015
    Link to this post
    Hi Dan,

    I have just replied in the ticket you have opened related to this. Here is my reply for your convenience:

    Please try to use the ResolveMediaUrl() in order to retrieve the relative url of the image:

    string relativeUrl = image.ResolveMediaUrl();

    You may also refer to the below article from our documentation where you can find a sample for this:

    Retrieve image url

    Sabrie Nedzhip
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
2 posts, 0 answered