ASP.NET Middleware doesn't preserve culture anymore

后端 未结 2 993
礼貌的吻别
礼貌的吻别 2021-01-18 12:17

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 thing

相关标签:
2条回答
  • 2021-01-18 12:59

    This article looks like what you need.

    Are you using the app.UseRequestLocalization(); in the Configure method?

    UPDATE

    Have a look at this module. I've downloaded the sample and it works (you have to update some nuget packages to be able to build it.) The sample works by providing the culture in the url, but that can be configured. This works with .NET 4.6.1.

    0 讨论(0)
  • 2021-01-18 12:59

    I Opened a support case at microsoft here there reply:

    Thanks for reporting the issue. we had a change in the setting the current cultures in 4.6. the change is setting the current cultures travel with the async operations. so if you set the culture during the async operation will affect the current async execution context and when the async operation is done and switch back to the original execution context, the culture will get reset to the culture in that context. you may read more about that in the like https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(v=vs.110).aspx#Async

    We still provide a way for you to get the old behavior if you want to. you can get back to the old behavior by executing the following code in the your app initialization:

    static string NoAsyncCurrentCultureFlagName = @"Switch.System.Globalization.NoAsyncCurrentCulture";
    AppContext.SetSwitch(NoAsyncCurrentCultureFlagName, true);
    
    0 讨论(0)
提交回复
热议问题