MediaUrl vs ItemDefaultUrl

Posted by Community Admin on 04-Aug-2018 18:04

MediaUrl vs ItemDefaultUrl

All Replies

Posted by Community Admin on 21-Sep-2015 00:00

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 "www.mysite.com/.../slide1.jpg. 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?

Thanks
Dan

Posted by Community Admin on 24-Sep-2015 00:00

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


Regards,
Sabrie Nedzhip
Telerik
 
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
 

This thread is closed