Get the Url to the EPiServer start page incl. language branch

This is how to retrieve the address to the startpage including the currently active language branch (e.g. “/sv/” or “/en/”):

PageData pagedata = Global.EPDataFactory.GetPage(Global.EPConfig.StartPage);
string url = pagedata.DetermineAutomaticURL(LanguageContext.Current.CurrentLanguageBranch);

This code looks simple but it actually took me an hour or so to get it right (I haven’t worked with globalization before) so I thought it’d make a good blog post…

/Emil

4 thoughts on “Get the Url to the EPiServer start page incl. language branch”

  1. I have unfortunately not worked with CMS 5 yet so I’m afraid I cannot help you out…

    If you solve your problem, then feel free to post the solution here 🙂

    Cheers,

    Emil

  2. I’ve posted a sample of getting the start page url in EPiServer CMS 5 (or later) at http://labs.kaliko.com/2010/10/get-start-page-url-in-episerver-cms-5.html

    Here’s the code:
    PageData pagedata = Global.EPDataFactory.GetPage(new PageReference(EPiServer.Configuration.Settings.Instance.PageStartId));
    EPiServer.UrlBuilder url = new EPiServer.UrlBuilder(pagedata.LinkURL);
    EPiServer.Global.UrlRewriteProvider.ConvertToExternal(url, pagedata.PageLink, System.Text.UTF8Encoding.UTF8);

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.