0

In my View the culture value is right. But in my ajax HttpPost method the culture is wrong. My goal is check url lang if empty check cookie if it is again empty I get the language from client(English,German,Turkish) default is TUrkish if client have another lang. I try to explain with example. My framework is 4.7.2

Here is my OnActionExecuting:

protected override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        if (filterContext.HttpContext.Request.HttpMethod == "GET")
        {
            var domainLang = RouteData.Values["lang"] as string;
            if (!string.IsNullOrEmpty(domainLang) && !string.IsNullOrWhiteSpace(domainLang))
            {
               //CurrentInfo is my class it is getting values from DB for once
                bool avaibleLang = CurrentInfo.AvailableLanguages.Count(x => x.DilKey == domainLang) > 0;
                if (avaibleLang)
                {
                    var langCookie = CurrentInfo.CurrentLang;
                    if (domainLang != langCookie.DilKey)
                    {
                        ClientCookieManagement.CreateCookie(CookieEnum.Language.GetStringValue(), domainLang, 7);
                    }
                }
                else
                {
                    domainLang = CurrentInfo.CurrentLang.DilKey;
                }
            }
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(domainLang ?? CurrentInfo.CurrentLang.DilKey);
        }

        base.OnActionExecuting(filterContext);
    }

I check my culture in view and it is right.

@Thread.CurrentThread.CurrentUICulture
@Thread.CurrentThread.CurrentCulture

But if I submit or post something with ajax the culture is wrong

CultureInfo.CurrentUICulture

My webconfig

<globalization culture="tr-TR" -uiCulture="tr-TR"/> Default lang is TR 

PROBLEM:

I need get the right value in my controller if I submit or anything else. What am I doing wrong?

Alican Kablan
  • 399
  • 8
  • 17
  • 1
    the code example that u have shared contains an 'if' condition for 'GET' type method and ur question is around POST type. Seems like u don't do anything when the method is POST type. Is something missing ? – akg179 Sep 18 '19 at 17:17
  • @akg179 omg thank you man I forget it. You save my night thank you. – Alican Kablan Sep 18 '19 at 19:18

0 Answers0