how to get friendly urls for image properties


Hi guys,

Consider you have the following image property

public virtual Url FeatureImage { get; set; }

Now Writing the follwing in webforms returns the non friendly url 

<%=this.currentpage.featureimage %>

How can I get the friendly url of this image? (Note, i don't want to use EPiServer:Property control as using that will return friendly url but i can't to use that)


Apr 21, 2015 13:45

Have you tried:

string linkUrl = string.Empty;
		PermanentLinkMapStore.TryToMapped(CurrentBlock.FeatureImage.Uri.ToString(), out linkUrl);
Apr 21, 2015 14:39

If you had used MVC you could have used @Url.ContentUrl(Model.CurrentPage.FeatureImage) but I do not know it that is possible in webform.

What you can do is to wrap that in a function that use this code:

var urlHelper = ServiceLocator.Current.GetInstance<UrlHelper>();
var friendlyUrl = urlHelper.ContentUrl([PASSED LINK TO FUNCTION]);


It is more explained here:

Edited, Apr 21, 2015 15:23
PermanentLinkMapStore.TryToMapped(CurrentBlock.FeatureImage.Uri.ToString(), out linkUrl); returns something like /link/e5d12600-ec7d-4592-a124-f08a525caa94.aspx?id=1111&epslanguage=en

There is no method ContentUrl on UrlHelper class.Also, None of other methods mentioned in other thread worked :(. 

All i am doing is on model


public virtual Url UrlToImage{get;set;}

and in the aspx page

<%=this.CurrentPage.UrlToImage %>

but it shows something like /link/e5d12600-ec7d-4592-a124-f08a525caa94.aspx?id=1111&epslanguage=en

Property control renders it correctly by showing something /global/a.jpg.

but i dont want (can't) use property control.

Any other suggestions guys?

Apr 24, 2015 16:34

The following code sample should give you friendly url. (there is no error checking in this code)

 var urlHelper = ServiceLocator.Current.GetInstance<UrlResolver>();
var friendlyUrlBuilder = new UrlBuilder(this.CurrentPage.NewLogoUrl.ToString());
ContentReference contentReference = PermanentLinkUtility.GetContentReference(friendlyUrlBuilder);
 string url = urlHelper.GetUrl(contentReference);

return url;

I am unsure if this is the best way of doing it but it seems to be working fine.

Apr 24, 2015 17:08
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.