net, which uses the use of Mvc (5.2.3) and WebApi (2.2). Now my application is built and initialized by the owin launcher class (Global.asax has been removed) with the Microsoft.Owin.Host.SystemWeb package installed.
Previously, in the Global.asax era, I set up the current request culture by taking the culture from a cookie or AcceptLanguage and setting Thread.CurrentThread.CurrentCulture = new CultureInfo (langSelectedValue) even for CurrentUiCulture.
Now that my Global.asax has passed away, leaving the setting in Startup.cs, the code that mimics the previous culture setting is in
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 obvious, all async requests lose Thread culture. I have tried many solutions:
- owin globalization module, but this is not for me, I do not want to change my attribute-based routing ...
- synchronization text to preserve and apply the culture, but the webapi / mvc stack, even if I set my own SynchronizationContext, continue to use AspNetSynchronizationContext
- WithCulture () extension methods with custom Awaiter for culture but nothing is done
I appreciate any suggestion to apply CultureInfo and save it in an asynchronous Owin application.
Thank you in advance
source share