I have an web application running in mobile application(WebView).When user open the app, mobile app sends me the language info of the telephone through the request. Since the language value comes only on the first request and then deleted, I have to take it and store it for subsequent requests. I have tried PreRequestHandlerExecute and Application_AcquireRequestState on global.asax. I control the Session. if it is null I get the value from request, if it is not null I get it from session. But it seems like session is always null and always get the value from request. Any idea would be very helpful? Thanks for advance.
var dilKodu = Request.Headers.GetValues("languageCode");
CultureInfo ci;
if (dilKodu != null)
{
//I set culture from request if it is not null.
ci = new CultureInfo(dilKodu[0].ToString());
this.Session["Culture"] = ci;
}
else
{
if (HttpContext.Current.Session != null)
{
//I get culture from Session if its set before.
ci = (CultureInfo)this.Session["Culture"];
if (ci == null)
{
string langName = "tr";
//If culture exist neither Session nor Request
ci = new CultureInfo(langName);
this.Session["Culture"] = ci;
}
}
else
{
ci = new CultureInfo("tr");
}
}
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);