Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

Get site hostname for each language?


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

Dec 13, 2013 16:24

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()

Dec 13, 2013 18:08

Any example code you could provide?

Dec 16, 2013 11:35

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);

Dec 16, 2013 12:59

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?

Dec 16, 2013 14:19

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

Edited, Dec 16, 2013 14:20

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

Dec 16, 2013 14:24

Thanks, Johan your solution helped me as well

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.