Given
asp.net 4 with mvc 5.2.3 and .net 4.6.1
I want to change the CurrentCulture support globalization based on some request related things like the host.
A Owin-Middleware which sets a culture.
Simplified Version which produces the behavior:
public override async Task Invoke(IOwinContext context)
{
var culture = new CultureInfo("es-ES");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;
await Next.Invoke(context);
}
Problem:
The Culture isn't preserved So for example a Web Controler doesn't have the culture which was set in the middleware.
This doesn't seem to be related to the thread culturepreserve issue. As when calling just some methods and awaiting them the culture is preserved.
Although with 4.5.1 it works. (I already used it this way in other projects) And when I change the httpRuntime version like this:
<httpRuntime targetFramework="4.5.1" />
everything works like a charm.
I can't find any documented breaking change for this. any hint? I can reproduce it with an empty new ASP Project Any advice?
An addition.
This problem is not related to culture preservation on thread as this works fine !
CultureInfo.CurrentCulture = new CultureInfo("en-GB");
await Foo();
Debug.WriteLine(Thread.CurrentThread.CurrentCulture);// Works is en-gb
}
private Task Foo()
{
Debug.WriteLine(Thread.CurrentThread.CurrentCulture);// Works is en-gb
return Task.FromResult(true);
}