Enabling Client-Based Culture in Core Asp.Net

In MVC 6, the default CultureInfo.CurrentCulture uses the one used by Windows, not the browser.

In MVC 5, I can put this in web.config :

 <globalization culture="auto" uiCulture="auto"/> 

and this will make CultureInfo.CurrentCulture the same as indicated in the browser ( Accept-Language header).

Is there a way to configure the MVC 6 application to use the default browser culture?

+5
source share
1 answer

You need to install the Microsoft.AspNet.Localization NuGet package and add the following to your Startup.cs :

 public void Configure(IApplicationBuilder app) { app.UseRequestLocalization(); app.UseMvc(); } 

By default, it registers AcceptLanguageHeaderRequestCultureProvider as a culture provider, which should be equivalent to the deprecated enableClientBasedCulture parameter.

Update:

According to your comment, since you are using the RC1 version, you should provide a default culture for this method. For instance:

 app.UseRequestLocalization(new RequestCulture("en")); 
+3
source

Source: https://habr.com/ru/post/1247011/


All Articles