Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Get site hostname for each language?

Vote:
0

Is it possible to get each hostname(s) for each language for a site in codebehind?

#79351
Dec 13, 2013 16:24
Vote:
0

There is a class EPiServer.Globalization.HostLanguageResolver that might help you. There is a method GetHostForLanguage that you can use. The second parameter is the siteUrl for the site you want a host for, to use current site you can pass in EPiServer.Web.SiteDefinition.Current.SiteUrl.ToString()

#79356
Dec 13, 2013 18:08
Vote:
0

Any example code you could provide?

#79384
Dec 16, 2013 11:35
Vote:
0

Below is some code that iterates over all enabled languages and checks if they are mapped to a specific host (for current site). Note that the method returns null if the langauge is not mapped.

var languageHostResolver = ServiceLocator.Current.GetInstance<HostLanguageResolver>();
var currentSiteUrl = SiteDefinition.Current.SiteUrl.ToString();
foreach (var languageBranch in ServiceLocator.Current.GetInstance<ILanguageBranchRepository>().ListEnabled())
{
        var host = languageHostResolver.GetHostForLanguage(languageBranch.LanguageID, currentSiteUrl);
}

#79391
Dec 16, 2013 12:59
Vote:
0

This dosen't work: var currentSiteUrl = SiteDefinition.Current.SiteUrl.ToString();

I get the error: 'EPiServer.Licensing.Services.SiteDefinition' does not contain a definition for 'Current'

What reference am i missing?

#79399
Dec 16, 2013 14:19
Vote:
0

SiteDefinition resides in EPiServer.Web namespace (in EPiServer.dll)

#79400
Edited, Dec 16, 2013 14:20
Vote:
0

Thanks, found it the second you reply. Now it works. :)

#79401
Dec 16, 2013 14:24
Vote:
0

Thanks, Johan your solution helped me as well

#178988
May 29, 2017 12:02
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.