无法在ASP.Net Core应用中设置默认和唯一区域性 [英] Cannot set default and only culture in ASP.Net Core app

查看:90
本文介绍了无法在ASP.Net Core应用中设置默认和唯一区域性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究波兰操作系统:

I'm working on Polish operating system:

在我的Statup.cs课堂上,我有以下代码

In my Statup.csclass I have following code

        // Configure the localization options
        var supportedCultures = new[]
        {
            new CultureInfo("en-GB")
        };

        app.UseRequestLocalization(
            new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("en-GB"),
                SupportedCultures = supportedCultures,
                SupportedUICultures = supportedCultures,
                FallBackToParentCultures = true,
                FallBackToParentUICultures = true,
                RequestCultureProviders = null
            });

完整选项仅供参考,以确保未设置任何内容.在我的_Layout.cshtml中,我有以下代码:

The full options are for reference only to be sure that nothing is set behind. In my _Layout.cshtml I have following code:

<div>Current Culture: @CultureInfo.CurrentCulture.DisplayName</div>
<div>Current UI Culture: @CultureInfo.CurrentUICulture.DisplayName</div>

唯一受支持和可用的区域性应该是en-GB,但是在网站上始终显示:

The only supported and available culture should be en-GB, however on web site it is always showing:

Current Culture: Polski (Polska)
Current UI Culture: Polski (Polska)

我尝试添加Microsoft.AspNet.Localization程序包,但这没什么区别.基于本地化中间件中的代码,所有工具均应按预期工作.我正在运行最新版本的ASP.NET Core 1.0.0.

I've tried to add Microsoft.AspNet.Localization package, but it makes no difference. Based on code in localization middleware, all should work as expected. I'm running latest version of ASP.NET Core 1.0.0.

推荐答案

有一件重要的事情,文档中没有提到. UseRequestLocalization必须放在UseMvc之前,我的位置在下面.

There is one important thing, not mentioned in documentation. UseRequestLocalization has to be placed before UseMvc, mine was below.

这篇关于无法在ASP.Net Core应用中设置默认和唯一区域性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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