Dmitry Sikorsky

ASP.NET Core Culture Route Parameter

This time we will see how to setup the MVC routing system to get culture as the URL segment:

ASP.NET Core Culture Route Parameter

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 RequestCultureProvider class:

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 RouteDataRequestCultureProvider class (it has been introduced in ASP.NET Core 1.1). It is described in this article (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.

Tuesday, December 05, 2017 by Dmitry Sikorsky