Thread.CurrentThread.CurrentUICulture in asp.net Core

纵饮孤独 提交于 2019-12-12 02:25:14

问题


In my MVC application I have had the following line and it has worked fine.

if (Thread.CurrentThread.CurrentUICulture.Name == localizationItem.CultureInfo.Trim())

Now as I am porting my application over to .Net Core 1.1, it appears that CurrentUICulture has went missing in action. Any ideas on what it's replacement is?

Severity Code Description Project File Line Suppression State Error CS1061 'Thread' does not contain a definition for 'CurrentUICulture' and no extension method 'CurrentUICulture' accepting a first argument of type 'Thread' could be found (are you missing a using directive or an assembly reference?) framework..NETCoreApp,Version=v1.1


回答1:


I believe you're looking to do localization.

Have a look here on how you can do it

Once it's setup, you can use something like this to get the current culture for a user:

var rqf = Request.HttpContext.Features.Get<IRequestCultureFeature>();
var culture = rqf.RequestCulture.Culture;


来源:https://stackoverflow.com/questions/42540599/thread-currentthread-currentuiculture-in-asp-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!