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