Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
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()
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);
}
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?
SiteDefinition resides in EPiServer.Web namespace (in EPiServer.dll)
Is it possible to get each hostname(s) for each language for a site in codebehind?