- Kentico Xperience 13
Localizing 404 page in Kentico Xperience 13
In this post I will provide you with code that will localize your 404 page in your Kentico Xperience 13 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
forcs-CZ
default culture) - URL paths for other cultures contain culture code (i.e.
/en-us/articles
foren-US
culture)
The solution
There are a couple of code files that you have to create.
HttpErrorsController.cs
Loading...NotFoundSiteCultureConstraint.cs
Loading...NotFound.cshtml 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.
Loading...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.
Loading...About the author
Milan Lund is a Freelance Web Developer with Kentico Expertise. He specializes in building and maintaining websites in Xperience by Kentico. Milan writes articles based on his project experiences to assist both his future self and other developers.
Find out more![Milan Lund](/_next/image?url=%2Fimg%2Fme.jpg&w=1920&q=75)