Force locale with Asp.Net Core

前端 未结 3 2112
不知归路
不知归路 2021-02-10 01:17

I\'m having some odd issues with a web application written using Asp.Net Core 1.1, using the full .Net Framework v4.6.2.

I want to force the application to use a swedish

3条回答
  •  心在旅途
    2021-02-10 01:45

    I had a similar issue with ASP Net Core 3.0. The site hosting was in a different country causing issues with formats.

    I added the following to the startup:

    using Microsoft.AspNetCore.Localization;
    using System.Globalization;
    

    in ConfigureServices:

    services.AddLocalization();
    

    in Configure:

    var supportedCultures = new[]{
        new CultureInfo("en-US")
    };
    app.UseRequestLocalization(new RequestLocalizationOptions {
        DefaultRequestCulture = new RequestCulture("en-US"),
        SupportedCultures = supportedCultures,
        FallBackToParentCultures= false
    });
    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
    

提交回复
热议问题