多区域项目中特定区域的多文化

multi cultures for specific one area in multi area project

我有一个项目,它有多个区域 我只想在一个领域应用文化。我使用文化但这对另一个领域有副作用你有解决问题的想法

例如:double in ajax请求转换为字符串 更改了另一个区域的货币类型

您根据特定区域的路线按要求手动设置文化:

public class CustomRouteDataRequestCultureProvider : RequestCultureProvider
{
    public int IndexOfCulture;

    public override Task<ProviderCultureResult> DetermineProviderCultureResult(HttpContext httpContext)
    {
        if (httpContext == null)
            throw new ArgumentNullException(nameof(httpContext));

        ProviderCultureResult providerResultCulture;

        if (httpContext.Request.Path.Value.Contains("your-area-path"))
            providerResultCulture = new ProviderCultureResult("en");
        else
            providerResultCulture = new ProviderCultureResult("fa");

        return Task.FromResult(providerResultCulture);
    }
}

并在启动中 class:

services.Configure<RequestLocalizationOptions>(options =>
{
    var supportedCultures = new CultureInfo[]
    {
        new CultureInfo("fa"),
        new CultureInfo("en")
    };

    options.DefaultRequestCulture = new RequestCulture("fa");
    options.SupportedCultures = supportedCultures;
    options.SupportedUICultures = supportedCultures;

    options.RequestCultureProviders = new[] { new CustomRouteDataRequestCultureProvider { IndexOfCulture = 0 } };
});