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?