Get friendly Url from Url property


I'm having a problem when trying to render an Url from an Url property in my view. Problem is that I want the friendly URL either it's an internal nor an external link. I can get the external link correct only by typing @Url.PageUrl(Model.Link.ToString()) but for the internal link this only gives me the ID to the page. How to get this done for both internal and external links?

Apr 25, 2014 10:30

If you are using MVC, then I would suggest to use @Url.Content()

Apr 27, 2014 6:53

You can also us UrlResolver.current. As well

Apr 28, 2014 5:16

Assuming that you've defined the link property like this:

public virtual Url Link { get; set; }


You can use the following code in your view:



Or you can use the following code in your controller:

var urlHelper = ServiceLocator.Current.GetInstance<UrlHelper>();
var friendlyUrl = urlHelper.ContentUrl(currentPage.Link);


Hope this helps.

Edited, Apr 28, 2014 22:44

Thanks, found what I was looking for here.

This is one of the most confusing areas of EPiServer, getting urls to things. UrlBuilder, UrlResolver, UrlHelper, UrlRewriteProvider, PermanentLinkUtility, PermanentLinkMapStore etc. It's just too many options. It shouldn't have to be this hard.

May 19, 2014 16:34

UrlResolver should be your first stop in EPiServer 7.5+.  the others are from previous versions.  Hopefully that helps you decide which on to use.

May 19, 2014 16:36

Aha, is that so.

In my case the only thing that made sense was UrlHelper.

I have an Url property that I want to get the link for, outside of a view. How am I supposed to do it?

May 19, 2014 16:55

UrlHelper uses UrlResolver under the hood

public static string ContentUrl(this UrlHelper urlHelper, Url url)
    if (url == null || url.IsEmpty())
    return string.Empty;
    return ServiceLocator.Current.GetInstance<UrlResolver>().ConvertClassicToContentUrl(url.ToString()) ?? url.ToString();

May 19, 2014 16:59

Ah, right, thanks!

May 19, 2014 17:05

Turns out ConvertClassicToContentUrl cannot be accessed, it's internal.

And it in turn uses UrlBuilder. :-P

May 19, 2014 17:07

Right, that is why they wrapped it in a helper "CotnentUrl".  

May 19, 2014 17:09
Tim Schmelter - Apr 19, 2021 16:07
So what is the correct way to resolve the url-string from an Url (not ContentReference) if you are in the controller?
* 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.