MediaUrl vs ItemDefaultUrl - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

MediaUrl vs ItemDefaultUrl

  • MediaUrl vs ItemDefaultUrl
  • 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 "localhost:60876/.../slide1.jpg

    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?


  • 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