How to get the friendly URL of a page in EPiServer CMS

by: Ted Nyberg (Hallvarsson & Halvarsson)

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


Comments

  1. Great code snippet!!
  2. Great!!
  3. Very useful, thanks Ted.
  4. Thanks Ted, very helpful.
  5. Great. Why isn't this built in?
  6. Thank u ..u made my day
Post a comment    
User verification Image for user verification  
Ted Nyberg (Hallvarsson & Halvarsson)

About me

I work for the corporate communications consultancy Hallvarsson & Halvarsson in Stockholm, Sweden.

My main focus areas are architecture, design and implementation of online applications such as public web sites and intranets.

Live Messenger

Hallvarsson & Halvarsson logo
 MCPD, MCTS and MCP logos


Syndications


Archive


Tag cloud

EPiTrace logger