# Troubleshooting incorrect CultureInfo in Ajax queries

**URL:** <https://forum.litium.com/t/troubleshooting-incorrect-cultureinfo-in-ajax-queries/2193>\
**Category:** Questions\
**Tags:** litium-7\
**Created:** [September 1, 2021, 6:44am UTC](https://forum.litium.com/t/troubleshooting-incorrect-cultureinfo-in-ajax-queries/2193 "2021-09-01T06:44:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![StephenM](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@StephenM](https://forum.litium.com/u/StephenM)\
**Post date:** [September 1, 2021, 6:44am UTC](https://forum.litium.com/t/troubleshooting-incorrect-cultureinfo-in-ajax-queries/2193/1 "2021-09-01T06:44:57Z")

</div>

We have a case where the CultureInfo.CurrentUICulture is incorrect in Ajax requests which appear to only occur in our development environment (QA and production both generate expected results)

Here is a specific scenario: CartController.AddVariantToCart (mvc controller POST query)  
My dev machine has culture en-GB and the site I am running uses sv-SE. Like in the accelerator, we read out the headers from an ajax query in the RequestModelHandler to determine the channel and from that we can set the CurrentUICulture. During an Ajax query and the AddVariantToCart action, this is works. I see the channelSystemId retrieved from the headers and set the CurrentUICulture to sv-SE. BUT when the code enters the AddVarantToCart method, the CurrentUICulture is en-GB again! Something is reverting the culture back to my system culture.

In a clean accelerator I don’t see this behavior. Of course the 7.6.3 accelerator uses a WebApi AddVariantToCart method and a call is made from react, while our code is still doing it in the Accelerator v5 way. But this being the result of old jQuery calls versus react/fetch calls seems unlikely, and even if moving the AddVariantToCart to a WebApi function would get around the problem, this is just one example and it would be a lot of work to do this for all Ajax calls.

Any thoughts or suggestions? Perhaps someone else with a similar experience who has solved it?

Thanks, Stephen

Litium version: 7.6.3

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [September 1, 2021, 7:20am UTC](https://forum.litium.com/t/troubleshooting-incorrect-cultureinfo-in-ajax-queries/2193/2 "2021-09-01T07:20:31Z")

</div>

From Litium 7 the Accelerator code a new header was included in all xhr communication, that is the header `litium-request-context` that contains the channel, page, category and product information so the web api can find the correct settings for the request.

Ex

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/6b0e2db27934aead506b565a19375f2b9f920780.png)

The setting of this data is done by the filters that is found in the `Litium.Accelerator.Mvc\Routing` folder and the `RequestModelHandler` for web api requests.

So if you can do something similar and include that in your jQuery calls it should work.

---

<div class="post-metadata">

**Author:** ![StephenM](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@StephenM](https://forum.litium.com/u/StephenM)\
**Post date:** [September 1, 2021, 7:26am UTC](https://forum.litium.com/t/troubleshooting-incorrect-cultureinfo-in-ajax-queries/2193/3 "2021-09-01T07:26:49Z")

</div>

We are doing exactly this already. If I walk through the debugger I can parse out the information, find the correct channel and set the CurrentUICulture accordingly. That works!

But its when I get to the MVC Post method where the culture appears to be reverted.

I have a thought though, could the problem be that the RequestModelHandler is a DelegatingHandler which is a WebApi component? Perhaps actions taken here have no impact on the MVC pipeline?

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [September 1, 2021, 7:51am UTC](https://forum.litium.com/t/troubleshooting-incorrect-cultureinfo-in-ajax-queries/2193/4 "2021-09-01T07:51:42Z")

</div>

If it is a MVC controller that is invoked outside the routing of Litium (not mapped to a CMS page) then you need to do similar thing for that request.

The `RequestModelHandler` are used for WebAPI and `RequestModelActionFilter` for regular MVC controllers. When the url is matching a page in the websites the culture is automatic be set, if url not is matching any pages Litium does not now what that should be mapped to.

---

<div class="post-metadata">

**Author:** ![StephenM](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@StephenM](https://forum.litium.com/u/StephenM)\
**Post date:** [September 2, 2021, 8:37am UTC](https://forum.litium.com/t/troubleshooting-incorrect-cultureinfo-in-ajax-queries/2193/5 "2021-09-02T08:37:33Z")

</div>

We do have, in this case, both the RequestModelHandler for WebApi AND RequestModelActionFilter for MVC (and RequestModelActionFilter is un-altered from the original Accelerator).

Of course, I can add setting CurrentUICulture here in this case, but it feels unnecessary. If the main MVC pipeline can determine channel and culture in a normal MVC request, why only set channel in an Ajax query calling a MVC Post method?

I’ve used the ServiceDecorator pattern to see what IChannelResolver is retrieving and it is definitely parsing a RouteRequestLookupInfo, so the information is available.

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [September 2, 2021, 8:43am UTC](https://forum.litium.com/t/troubleshooting-incorrect-cultureinfo-in-ajax-queries/2193/6 "2021-09-02T08:43:15Z")

</div>

Just to double-check - but `RequestModelActionFilter` is registered as a global filter too?

---

<div class="post-metadata">

**Author:** ![StephenM](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@StephenM](https://forum.litium.com/u/StephenM)\
**Post date:** [September 2, 2021, 10:10am UTC](https://forum.litium.com/t/troubleshooting-incorrect-cultureinfo-in-ajax-queries/2193/7 "2021-09-02T10:10:41Z")

</div>

Yup! That it is 👍

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [September 30, 2021, 10:11am UTC](https://forum.litium.com/t/troubleshooting-incorrect-cultureinfo-in-ajax-queries/2193/8 "2021-09-30T10:11:05Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
