我在使用ASP.NET Core MVC时遇到了一些小数问题。在常规的ASP.NET应用程序中,我通过将以下内容添加到web.config文件来解决该问题:
<system.web>
...
<globalization uiCulture="en" culture="en-US"/>
</system.web>
但是,由于核心应用程序中没有web.config文件,我不太确定该怎么做。在core中,最接近此的是什么?
我在使用ASP.NET Core MVC时遇到了一些小数问题。在常规的ASP.NET应用程序中,我通过将以下内容添加到web.config文件来解决该问题:
<system.web>
...
<globalization uiCulture="en" culture="en-US"/>
</system.web>
但是,由于核心应用程序中没有web.config文件,我不太确定该怎么做。在core中,最接近此的是什么?
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
请求的当前文化设置在本地化中间件中。本地化中间件在Startup.Configure
方法中启用。在可能检查请求文化的任何中间件之前(例如,app.UseMvcWithDefaultRoute()
),必须配置本地化中间件。
var supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("fr"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en-US"),
// Formatting numbers, dates, etc.
SupportedCultures = supportedCultures,
// UI strings that we have localized.
SupportedUICultures = supportedCultures
});
app.UseStaticFiles();
// To configure external authentication,
// see: http://go.microsoft.com/fwlink/?LinkID=532715
app.UseAuthentication();
app.UseMvcWithDefaultRoute();
如需更多细节,您可以参考官方文档。