Question

Just a sample scenario: When my javascript client retrieves data and that data access logic depends on a start- and enddate then their is also a dependency on the current culture because of the first date of the week for example.

Now I ask myself how I should design my asp.net web api layer to make the calls to the server aware of the current culture on the server Is this a one time action that when the user logs in the site that I also pass the current language or the lcid to the server and store it there and delete it when the user logs out.

And if yes where would you save that language setting, that my domain services can access this data too.

Or how would you make the server aware of the client side browser language?

Was it helpful?

Solution

ASP.NET Web API is for building HTTP services, which are generally considered stateless. So, I'd much rather pass the current culture in every request. Accept-Language request header is a good candidate to send this data across. Check this out. If you opt to use this approach, you can use a message handler in ASP.NET Web API pipeline to read the value off the Accept-Language request header and set the corresponding .NET culture in the thread (Thread.CurrentCulture).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top