title: Owin CultureInfo & AspNetSynchronizationContext
body: <p>net application which both makes usage of Mvc (5.2.3) &amp; WebApi (2.2). Now My application is built and initialized by owin Startup class (Global.asax has been deleted) with the package <strong>Microsoft.Owin.Host.SystemWeb</strong> installed.</p>
  
  <p>Previously, in the ages of Global.asax, I was setting up the <em>current request culture</em> by taking culture by cookie or AcceptLanguage header and setting up <strong>Thread.CurrentThread.CurrentCulture = new CultureInfo(langSelectedValue)</strong> even for CurrentUiCulture. </p>
  
  <p>Now, as my Global.asax has passed away leaving the setup in Startup.cs, the code to <em>mimic</em> the previous culture setup is in a </p>
  
  <pre><code>app.Use(async (env, next) =&gt; {
  var langCookie = env.Request.Cookies["cultureName"];
  if (langCookie != null &amp;&amp; GlobalizationHelper.IsValidCultureCode(langCookie))
  {
      Thread.CurrentThread.CurrentCulture = new CultureInfo(langCookie);
      Thread.CurrentThread.CurrentUICulture = new CultureInfo(langCookie);
  }
  await next();
  })
  </code></pre>
  
  <p>The problem is clear, all async requests get lost the Thread culture. I tried many solutions:</p>
  
  <ol>
  <li>the owin globalization module, but it's not for me, I don't want to change my routing, which is based on attributes...</li>
  <li>the synchronizationcontext for preserve and apply the culture, but the webapi/mvc stack even if I set my own SynchronizationContext continue using the AspNetSynchronizationContext</li>
  <li>the WithCulture() extension methods with a customized Awaiter for culture, but nothing done</li>
  </ol>
  
  <p>I appreciate any suggestion to apply the CultureInfo and preserve it in a Owin async application.</p>
  
  <p>Thanks in advance</p>