Render friendly URL in code behind


I'm trying to render a friendly url to add to a javascript click event in my markup. The URL I get isn't very friendly though. I use this code to get the url of the page and the necessary querystrings for languagebranches, etc, but how do I make it a friendly url?

string tellFriendPageUrl;
PageReference tellFriendPageRef = CurrentPage["TellFriend"] as PageReference;

if (tellFriendPageRef != null)
        PageData tellFriendPage = GetPage(tellFriendPageRef);
        tellFriendPageUrl = tellFriendPage.LinkURL;

Jan 27, 2010 10:40

You can convert between internal and external urls by using the UrlRewriteProvider:

You can get the current provider through the Global class in code:

EPiServer.Global.UrlRewriteProvider.ConvertToExternal(new UrlBuilder(myUrl), null, Encoding.UTF8);

Jan 27, 2010 10:53

I've tried using that but all I get is "True". I'm pretty sure I'm using it wrong.

Jan 27, 2010 10:59

Sorry, was a bit quick with the code sample there, try this:

var ub = new UrlBuilder(internalUrl);
EPiServer.Global.UrlRewriteProvider.ConvertToExternal(ub, null, Encoding.UTF8);
string externalUrl = ub.ToString();

The true value you get means that the conversion was successful.

Jan 27, 2010 11:03

That did the trick! Thanks a lot!

Jan 27, 2010 11:31
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.