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…