World is now on Opti ID! Learn more
AI OnAI Off
World is now on Opti ID! Learn more
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);
I've tried using that but all I get is "True". I'm pretty sure I'm using it wrong.
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.
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;
}