Try our conversational search powered by Generative AI!

Class HostLanguageResolver

Handles mappings from host to language.

Inheritance
System.Object
HostLanguageResolver
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Globalization
Assembly: EPiServer.dll
Version: 8.11.0
Syntax
[ServiceConfiguration(typeof(HostLanguageResolver), Lifecycle = ServiceInstanceScope.Singleton)]
public class HostLanguageResolver

Constructors

HostLanguageResolver(SiteDefinitionRepository)

Initializes a new instance of the HostLanguageResolver class.

Declaration
[Obsolete("Use alternative constructor")]
public HostLanguageResolver(SiteDefinitionRepository siteDefinitionRepository)
Parameters
Type Name Description
SiteDefinitionRepository siteDefinitionRepository

HostLanguageResolver(SiteDefinitionRepository, IEventRegistry)

Initializes a new instance of the HostLanguageResolver class.

Declaration
public HostLanguageResolver(SiteDefinitionRepository siteDefinitionRepository, IEventRegistry eventRegistry)
Parameters
Type Name Description
SiteDefinitionRepository siteDefinitionRepository
IEventRegistry eventRegistry

Properties

HostLanguageMappings

Gets the host language mappings.

Declaration
public virtual StringDictionary HostLanguageMappings { get; }
Property Value
Type Description
System.Collections.Specialized.StringDictionary

The host language mappings.

Remarks

This property is used to map a host name, such as www.company.com, to a specific language.

Methods

GetDefaultHostLanguage()

Gets the default host language.

Declaration
public virtual string GetDefaultHostLanguage()
Returns
Type Description
System.String

A string that is a culture name. If no language defined for default host (name="*"), returns null.

Remarks

This code performs its work based on the information in the <siteHostsMappings> section in EPiServerFramework.config.

GetHostForLanguage(String, String)

Gets the host for specified language given site specified by siteUrl.

Declaration
[Obsolete("Use SiteDefinition.PrimaryHost() instead")]
public virtual string GetHostForLanguage(string language, string siteUrl)
Parameters
Type Name Description
System.String language

The language.

System.String siteUrl

The site URL.

Returns
Type Description
System.String

GetHostsForLanguage(String, String)

Gets the hosts that is mapped for specified language given site specified by siteUrl.

Declaration
[Obsolete("Use SiteDefinition.GetHosts() instead")]
public virtual IEnumerable<string> GetHostsForLanguage(string language, string siteUrl)
Parameters
Type Name Description
System.String language

The language.

System.String siteUrl

The site URL.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.String>

GetLanguageForHost(String, Boolean)

Gets the language mapping defined for a host.

Declaration
public virtual string GetLanguageForHost(string hostName, bool fallback)
Parameters
Type Name Description
System.String hostName

Name of the host.

System.Boolean fallback

if set to true then it fallsback and checks if wildcard mapped host has language mapping.

Returns
Type Description
System.String

GetLanguageFromRequest(HttpRequestBase)

Gets the language to use based on the host name.

Declaration
public virtual string GetLanguageFromRequest(HttpRequestBase request)
Parameters
Type Name Description
System.Web.HttpRequestBase request
Returns
Type Description
System.String

A string that is a culture name. If no match found, returns null.

Remarks

This code performs its work based on the information in the <siteHostsMappings> section in EPiServerFramework.config.

IsHostLanguageMatch(String, String)

Determines whether the provided host is mapped to the provided language as defined either by direct hostname-to-language mapping or through wildcard language mapping.

Declaration
public virtual bool IsHostLanguageMatch(string hostName, string language)
Parameters
Type Name Description
System.String hostName

The name of the host to verify.

System.String language

The language to check.

Returns
Type Description
System.Boolean

true if the languages math; otherwise, false.

Remarks

The hostname to language mapping is defined by the SiteDefinition API . The purpose of this is that the language indicator segment in the URL is not needed when you have a match between the requested language and the default language as indicated by the host name.

IsHostLanguageMatch(HttpRequestBase, String)

Determines whether the requested language matches the default language as defined by a hostname-to-language mapping.

Declaration
[Obsolete("Use overload with hostname instead")]
public virtual bool IsHostLanguageMatch(HttpRequestBase request, string language)
Parameters
Type Name Description
System.Web.HttpRequestBase request

The request.

System.String language

The requested language.

Returns
Type Description
System.Boolean

true if the languages math; otherwise, false.

Remarks

The hostname to language mapping is defined in the configuration file (by default EPiServerFramework.config, <siteHostsMapping> section). The purpose of this is that the language indicator segment in the URL is not needed when you have a match between the requested language and the default language as indicated by the host name.

Extension Methods