ASP.NET Core中的Thread.CurrentThread.CurrentUICulture [英] Thread.CurrentThread.CurrentUICulture in asp.net Core

查看:177
本文介绍了ASP.NET Core中的Thread.CurrentThread.CurrentUICulture的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的MVC应用程序中,我有以下一行,并且运行良好.

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

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

现在,当我将应用程序移植到.Net Core 1.1时, CurrentUICulture 似乎已经消失了.关于替换它的任何想法是什么?

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?

严重性代码描述项目文件行抑制状态 错误CS1061线程"不包含以下内容的定义: "CurrentUICulture",没有扩展方法"CurrentUICulture" 可以找到接受类型为线程"的第一个参数(您是 缺少using指令或程序集 参考?)framework..NETCoreApp,Version = v1.1

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

推荐答案

我相信您正在寻求本地化.

I believe you're looking to do localization.

此处有关如何操作它

设置完成后,您可以使用类似的方式为用户获取当前的区域性:

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;

这篇关于ASP.NET Core中的Thread.CurrentThread.CurrentUICulture的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆