最佳答案
我要疯了。我只是希望在整个 Asp.net 核心应用程序中使用的文化设置为“ en-US”。但似乎没什么效果。将整个应用程序的区域性设置到哪里?我对客户浏览器文化之类的不感兴趣。唯一改变它的似乎是改变 Windows 的语言设置。我只希望从应用程序本身而不是由客户机来确定区域性。
到目前为止我所做的努力:
<system.web><globalization uiCulture="en" culture="en-US" /></system.web>
System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo;
和 CurrentUICulture
。配置甚至在控制器中。使用如下所示的 app.UseRequestLocalization(..
var enUsCulture = new CultureInfo("en-US");
var localizationOptions = new RequestLocalizationOptions()
{
SupportedCultures = new List<CultureInfo>()
{
enUsCulture
},
SupportedUICultures = new List<CultureInfo>()
{
enUsCulture
},
DefaultRequestCulture = new RequestCulture(enUsCulture),
FallBackToParentCultures = false,
FallBackToParentUICultures = false,
RequestCultureProviders = null
};
app.UseRequestLocalization(localizationOptions);
But nothing seems to change the CurrencyDecimalSeparator from (nl-NL) , to (en-US).
How can the culture be set?
EDIT:
@soren
This is how the configure method looks like. I've put a breakpoint on DetermineProviderCultureResult
but it is never hit while visiting the website.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, FinOsDbContext context)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseIdentity();
// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
//TODO: Clean up
//var cultureInfo = new CultureInfo("en-US");
//System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo;
//System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo;
app.UseRequestLocalization();
// UseCookieAuthentication..
// UseJwtBearerAuthentication..
//add userculture provider for authenticated user
var requestOpt = new RequestLocalizationOptions();
requestOpt.SupportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US")
};
requestOpt.SupportedUICultures = new List<CultureInfo>
{
new CultureInfo("en-US")
};
requestOpt.RequestCultureProviders.Clear();
requestOpt.RequestCultureProviders.Add(new SingleCultureProvider());
app.UseRequestLocalization(requestOpt);
FinOsDbContext.Initialize(context);
FinOsDbContext.CreateTestData(context);
}
public class SingleCultureProvider : IRequestCultureProvider
{
public Task<ProviderCultureResult> DetermineProviderCultureResult(HttpContext httpContext)
{
return Task.Run(() => new ProviderCultureResult("en-US", "en-US"));
}
}