Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app.UseRequestLocalization overwritten on deployed IIS #58440

Open
1 task done
Schoof-T opened this issue Oct 15, 2024 · 4 comments
Open
1 task done

app.UseRequestLocalization overwritten on deployed IIS #58440

Schoof-T opened this issue Oct 15, 2024 · 4 comments
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-iis Includes: IIS, ANCM

Comments

@Schoof-T
Copy link

Schoof-T commented Oct 15, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In Blazor Server, when setting the app.UseRequestLocalization("en-GB"); I was under the assumption that your application should always use the "en-GB" culture.

This works correctly locally in my Visual Studio, I can switch the "en-GB" to any other locale and the whole app will switch.
However, I notice that after deploying my application to a local IIS server, the culture is still "en-GB" but for example the decimal seperator is different. (locally the decimal seperator is ".", deployed it's a ",")

It is still using the culture settings of the Windows user that is set as the identity of your application pool.

Image

Expected Behavior

  • Set app.UseRequestLocalization("en-GB");
  • Application always uses the same "en-GB" culture.

Steps To Reproduce

  • Create Blazor Web App (Server)
  • Add app.UseRequestLocalization("en-GB");
  • Build application self contained and for win-x64 (--self-contained true --runtime win-x64)
  • Deploy application to IIS
    Application pool is as follows:
    Image
    The Identity is a an account, with limited access.

Exceptions (if any)

No response

.NET Version

8

Anything else?

ASP.NET CORE 8
Blazor Server
Visual Studio 2022

cc: @guardrex dotnet/AspNetCore.Docs#33847

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Oct 15, 2024
@javiercn javiercn added feature-iis Includes: IIS, ANCM area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-blazor Includes: Blazor, Razor Components labels Oct 15, 2024
@Schoof-T
Copy link
Author

Schoof-T commented Oct 16, 2024

Investegating further I found that this has to do with the user account running the application pool. Looking in the registry I saw that the user has the Regional Settings of "en-GB", but the decimal seperator is set as ",". Which is different from the default.

I was under the assumption app.UseRequestLocalization("en-GB"); would ignore any user settings. Turns out this is not true.
To fully ignore user settings I had to do the following:

    var english = new CultureInfo("en-GB", false);
    var englishRequestCulture = new RequestCulture(culture: english, uiCulture: english);

    var options = new RequestLocalizationOptions
    {
        DefaultRequestCulture = englishRequestCulture,
        SupportedCultures = [english],
        SupportedUICultures = [english]
    };

    app.UseRequestLocalization(options);

Specifically the false parameter of new CultureInfo("en-GB", false); is very important.

Is this expected behaviour and is this a correct solution I have implemented?
If it is, It would be nice if this is documented somewhere. Apologies if I missed this in the documentation. :)

@guardrex
Copy link
Contributor

You didn't miss it in the documentation AFAIK. This never came up in discussions with the team or with @hishamco.

I'm 👁 on this issue, and I'll work on the guidance using the original docs issue after the product unit responds and lets us know what's going on and how to resolve it.

@hishamco
Copy link
Member

I'm in the mobile now, I will have a look once I open the laptop

@hishamco
Copy link
Member

Before I dig into that could you try to set CultureInfoUseUserOverride = false in the RequestLocalizationOptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-iis Includes: IIS, ANCM
Projects
None yet
Development

No branches or pull requests

4 participants