How to get the friendly URL of a page in EPiServer CMS
Maybe there are other posts about this, but I thought I'd share an easy way of getting the friendly URL of a page since I've gotten questions about it on numerous occasions:
public static string GetFriendlyURL(
PageReference PageLink,
string URL)
{
UrlBuilder url = new UrlBuilder(URL);
EPiServer.Global.UrlRewriteProvider.ConvertToExternal(
url, PageLink, System.Text.UTF8Encoding.UTF8);
return url.Uri.AbsoluteUri;
}
Note: you do not have to specify the PageLink parameter when calling the ConvertToExternal() method, but according to the SDK you will get the best performance when specifying both the PageLink parameter as well as the internal URL. So, you should probably not ignore the PageLink parameter unless you have to - URL rewriting is probably the most expensive operation carried out by EPiServer.
07 February 2008