【问题标题】:ASP.Net Core, setting current culture based on subdomain?ASP.Net Core,基于子域设置当前文化?
【发布时间】:2017-03-08 22:29:00
【问题描述】:

我试图弄清楚如何在 ASP.Net Core 1.1 中基于子域设置站点文化。

我的 Startup.cs

中有以下内容
services.Configure<RequestLocalizationOptions>(options =>
{
    var supportedCultures = new List<CultureInfo>
    {
        new CultureInfo("en-US"),
        new CultureInfo("fil-PH")
    };

    options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US");
    options.SupportedCultures = supportedCultures;
    options.SupportedUICultures = supportedCultures;
    if (UrlManagement.IsLocalizedUrl())
    {
        options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context =>
        {
                CultureInfo cultureInfo = UrlManagement.GetCultureInfoFromUrl();
            ProviderCultureResult providerCultureResult = await new ProviderCultureResult(cultureInfo.Name);
            return providerCultureResult;
        }));
    }
});

它在构建时抱怨这个错误。

“ProviderCultureResult”不包含“GetAwaiter”的定义 并且没有扩展方法“GetAwaiter”接受第一个参数 可以找到类型“ProviderCultureResult”(您是否缺少使用 指令还是程序集引用?)

如果我删除等待,那么它会抱怨我应该等待。

如果我删除异步,那么它会抱怨它应该是异步的。

【问题讨论】:

    标签: asp.net-core asp.net-core-mvc


    【解决方案1】:

    如果我删除等待,那么它会抱怨我应该等待。

    没有。它警告您,您的 async 函数没有任何 await 并将同步运行。这不是错误。你可以忽略这个。

    【讨论】:

    • 谢谢。插入 RequestCultureProvider 的建议方法会引发警告,这有点烦人。
    猜你喜欢
    • 2020-10-07
    • 2018-09-30
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多