Ali Kareem Raja
Ali Kareem Raja

Reputation: 576

WebApi is using Web Server culture

Our servers are running in Denmark using the Da-DK culture. We have not specified any culture in the ASP.NET WebApi solution.

When an endpoint is called on the Api with a decimal parameter, the api automatically converts it into European decimal notation (e.g. 100,01) which eventually results in a parsing error when the decimal is passed to another API on another server.

How can we force our Api to use the US culture and not the culture of the Web Server?

Upvotes: 2

Views: 1182

Answers (1)

tlt
tlt

Reputation: 15211

You need to set default localization for your app. In particular, you need UseRequestLocalization. There you have DefaultRequestCulture that you will want to set to your culture.

Take a look at ref: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization#provide-localized-resources-for-the-languages-and-cultures-you-support

[UPDATE] I have just realized you are not asking for asp.net core. For web api, you can go in with setting culture on Thread.Current

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

Upvotes: 2

Related Questions