I have .net core 2.1 Web Api project. And I'm sending GET request like below. I'm sending "10.12.2019" by postman. But I'm getting from controller as "12.10.2019". There was this issue in POST request. I fixed by adding below code to Startup.cs.But, problem continueing in GET request. How can I fix for GET request?
MyController.cs
[HttpGet]
public void MyGetMethod(DateTime myDate)
{ }
My Url
http://localhost:5012/api/MyController/MyGetMethod?myDate=10.12.2019
My Startup.cs
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.Culture = new CultureInfo("tr-TR");
});
///////////////////////////////
var defaultCulture = new CultureInfo("tr-TR");
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture(defaultCulture),
SupportedCultures = new List<CultureInfo> { defaultCulture },
SupportedUICultures = new List<CultureInfo> { defaultCulture }
});
DateTime.TryParsewith that string input from the GET-request. More like a work-around, but would be my advice. This would allow you to target the exact formatting you'd like.