November Happy Hour will be moved to Thursday December 5th.

Render friendly URL in code behind

Vote:
 

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;
    }

#36391
Jan 27, 2010 10:40
Vote:
 

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

http://sdk.episerver.com/library/CMS5/html/AllMembers_T_EPiServer_Web_UrlRewriteProvider.htm

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

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

#36392
Jan 27, 2010 10:53
Vote:
 

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

#36393
Jan 27, 2010 10:59
Vote:
 

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.

#36394
Jan 27, 2010 11:03
Vote:
 

That did the trick! Thanks a lot!

#36395
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.