我正在尝试将我的WEB API应用程序设置为接受包含以dd / mm / yyyy格式传递的DateTime属性的发布请求。
在我的Startup类中,我将请求本地化配置如下:-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
//app.UseAuthentication();
var supportedCultures = new[]
{
new CultureInfo("en-AU"),
new CultureInfo("en-GB"),
new CultureInfo("en"),
new CultureInfo("es-ES"),
new CultureInfo("es-MX"),
new CultureInfo("es"),
new CultureInfo("fr-FR"),
new CultureInfo("fr"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en-GB"),
// Formatting numbers, dates, etc.
SupportedCultures = supportedCultures,
// UI strings that we have localized.
SupportedUICultures = supportedCultures
});
app.UseMvc();
}
但是,模型绑定在测试日期(例如22/12/1977)失败。对我来说,中间件被忽略了。