How to prevent resolving of not registered languages

  • By default, Sitecore XP resolves the language from the part of the path that goes after the first forward-slash ("/") character:
    When a letter combination that matches any of the .NET Culture Codes is in that position, it gets resolved as a language (even if the language is not registered for Sitecore XP instance) and is not used to resolve anything else (for example, an alias or an item). If a resolved language is not identified, an error similar to the following appears:
    ERROR Attempt to register language failed. Language: custom-item-name-with-dashes
    Exception: System.UnauthorizedAccessException
    Message: Access to the path 'C:\Windows\Globalization\custom-item-name-with-dashes.nlp' is denied.
  • Possible ways to change the described behavior depend on the requirement to include the language as part of the URL.

    • If a specific website is not a multi-language one, and it does not require adding the language code to the URL, disable the Languages.AlwaysStripLanguage setting (change its value to false) in the /App_Config/Sitecore.config file.
    • If the website is a multi-language one, and it is necessary to prevent resolving of non-defined languages, consider implementing a custom ItemLanguageResolver processor. See the following link for a code sample:

Applies to:

CMS 6+

February 26, 2020
September 10, 2020