Milan Lund logo

Hi, I am Milan Lund!Full Stack Web Developer

I specialise in building websites and web applications with and Kentico platforms.

  • Kentico EMS & Xperience

Localizing 404 page in Kentico Xperience

In this post I will provide you with code that will localize your 404 page in your Kentico Xperience website.

The problem

In my Xperience website, I am using 2 cultures. When I was about to create a 404 page, I didn't want to re-invent the wheel. Therefore, I took out the 404 page implementation from the Dancing Goat site which is a sample site that comes with Kentico Xperience in one package.

Regrettably, I found out that the implementation is not ready for localization and must be adjusted to show localized strings. With the kind help of Kentico's support, I was able to find a solution.

Please note, that this solution is valid for URL structure where 

  • URL paths for the default culture do not contain culture code (i.e. "/clanky" for "cs-CZ" default culture)
  • URL paths for other cultures contain culture code (i.e. "/en-us/articles" for "en-US" culture)

The solution

There are a couple of code files that you have to create.





NotFound.cshtml - This is a view and it should contain your own markup that fits your website. Here I post an example that uses Localization strings. They could be defined in the Xperience Admin in the Localization application.


In the Startup.cs file, add the following code in the Configure method after endpoints.Kentico().MapRoutes();


And that's it.

Side notes

Considering the Dancing Goat site, the only extra piece in the implementation is the NotFoundSiteCultureConstraint.cs file. What I really like here is the way the originalTarget is obtained. You can also use that in your controller to add some extra logic to your 404 page.

Example - Redirects article details that are not localized to a listing page.