This time we will see how to setup the MVC routing system to get culture as the URL segment:
ASP.NET Core supports specifying culture using the URL parameter from the box, but the URL in this case should look like this:
In most cases you want to have something this instead:
One way to do it is to inherit the
This code checks whether the culture segment is present inside the URL. If it is not, the default culture is used. If the culture segment exists, it is checked again among the supported cultures.
Then we have to tell our web application to use request localization middleware with our culture provider class as an option:
Please note, that the default route registration contains the culture segment.
There is another one way to have the same result using the built-in
(it has been introduced in ASP.NET Core 1.1). It is described in
(don’t forget to mark your controllers with the
MiddlewareFilter attribute to make it work.).
I have created the demo project for this post on GitHub. Feel free to ask any questions.