Cannot set default and only culture in ASP.Net Core app

你说的曾经没有我的故事 提交于 2019-12-04 04:06:30

问题


I'm working on Polish operating system:

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
            });

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>

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)

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.


回答1:


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



来源:https://stackoverflow.com/questions/38497903/cannot-set-default-and-only-culture-in-asp-net-core-app

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