Get friendly Url of a page in EPiServer

There are several ways of getting a Url for a page.  If you want to get a friendly Url from a view, then I would strongly recommend reading this post to see all the options available to you: Creating a friendly URL within your EPiServer 7 MVC View with Route Data. If, however, you want a quick and easy way in code, then I would recommend using the following approach:

        public string GetFriendlyUrl(string linkUrl)
        {
            var url = new EPiServer.UrlBuilder(linkUrl);
            EPiServer.Global.UrlRewriteProvider.ConvertToExternal(url, page.PageLink, System.Text.UTF8Encoding.UTF8);

            return url.ToString();
        }
You can then call the method using:
var friendlyUrl = GetFriendlyUrl(pageData.LinkURL);

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top