I\'m having some odd issues with a web application written using Asp.Net Core 1.1, using the full .Net Framework v4.6.2.
I want to force the application to use a swedish
Take a look at Microsoft ASP.NET Core Docs - Globalization and localization.
4) Added RequestLocalization to Configure(...) in Startup.cs
From docs:
The current culture on a request is set in the localization Middleware. The localization middleware is enabled in the Configure method of Startup.cs file.
Note, the localization middleware must be configured before any middleware which might check the request culture (for example, app.UseMvc()).
5) In my controller constructor setting the current threads culture
6) In my controller actions setting the current threads culture
Instead of setting in the constructor or in every action, try set the culture at OnActionExecuting
filter. Here is an example code:
public class InternationalizationAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var cultureInfo = CultureInfo.GetCultureInfo("sv-SE");
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
}
}
In your controller class, put this: [Internationalization]
.
I had a similar issue with ASP Net Core 3.0. The site hosting was in a different country causing issues with formats.
I added the following to the startup:
using Microsoft.AspNetCore.Localization;
using System.Globalization;
in ConfigureServices:
services.AddLocalization();
in Configure:
var supportedCultures = new[]{
new CultureInfo("en-US")
};
app.UseRequestLocalization(new RequestLocalizationOptions {
DefaultRequestCulture = new RequestCulture("en-US"),
SupportedCultures = supportedCultures,
FallBackToParentCultures= false
});
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
Did you try setting the CultureInfo.CurrentCulture
property in Program.cs
:
using System.Globalization;
CultureInfo.CurrentCulture = new CultureInfo("sv-SE");