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

QueryStringRequestCultureProvider Does Not Work With Blazor Server #20346

Open
taoyouh opened this issue Mar 31, 2020 · 12 comments
Open

QueryStringRequestCultureProvider Does Not Work With Blazor Server #20346

taoyouh opened this issue Mar 31, 2020 · 12 comments
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-server feature-localization severity-major This label is used by an internal tool
Milestone

Comments

@taoyouh
Copy link

taoyouh commented Mar 31, 2020

Describe the bug

When using QueryStringRequestCultureProvider on Blazor Server, the culture immediately changes from the one given in query string to the one set in HTTP headers.

To Reproduce

// Startup.cs
app.UseRequestLocalization("zh-CN", "en");
// Index.razor
@CultureInfo.CurrentCulture.TextInfo

Launch the app with URL http://localhost:xxx/?culture=zh-CN. The page displays "zh-CN" for less than 1 second and changes to "en"

Further technical details

Version of .NET Core SDK:

 Version:   3.1.200
 Commit:    c5123d973b

运行时环境:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.200\

Host (useful for support):
  Version: 3.1.2
  Commit:  916b5cba26

.NET Core SDKs installed:
  2.1.508 [C:\Program Files\dotnet\sdk]
  2.1.509 [C:\Program Files\dotnet\sdk]
  2.1.801 [C:\Program Files\dotnet\sdk]
  3.1.200 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

IDE: Visual Studio 16.5.0

@mkArtakMSFT mkArtakMSFT added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-localization labels Mar 31, 2020
@javiercn
Copy link
Member

@taoyouh thanks for contacting us.

This is likely due to the url used to establish the connection with server-side Blazor.

@rynowak do you have any thoughts around this?

@SteveSandersonMS We could consider tackling query string parameters when we setup the connection to the hub so that things like this would possibly work. Do you have any opinions?

@javiercn javiercn added area-blazor Includes: Blazor, Razor Components and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Mar 31, 2020
@javiercn javiercn added this to the Next sprint planning milestone Mar 31, 2020
@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components and removed area-blazor Includes: Blazor, Razor Components labels Apr 24, 2020
@mkArtakMSFT
Copy link
Member

@anurse how does query string localization work in SignalR?

@analogrelay
Copy link
Contributor

SignalR doesn’t do anything with it. Any culture information on the HttpContext when it reaches SignalR should be preserved.

@javiercn
Copy link
Member

@anurse do you have any docs or thoughts on how to do this E2E for SignalR applications?

@analogrelay
Copy link
Contributor

Nope. It’s not something we’ve really thought about.

@AlexTeixeira
Copy link

Hi,

Same here. For info, If I debug the GetString Method, the correct culture is displayed.

@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Apr 28, 2020
@mkArtakMSFT
Copy link
Member

We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

@danroth27 danroth27 removed their assignment May 5, 2020
@pranavkm pranavkm added affected-few This issue impacts only small number of customers severity-major This label is used by an internal tool labels Oct 5, 2020
@mhudasch
Copy link

Hi, could recreate the problem in 5.0.2

I debugged through the RequestLocalizationMiddleware and yes the _blazor/ calls reset the current thread culture that is then used during the second call inside a razor component. I had a breakpoint inside the OnInitialized lifecycle hook and on first hit my injected IStringLocalizer instance had the correct string resolved. When the breakpoints hits the second time (which is expected when using blazor server/prerendered) the IStringLocalizer has a different result. Creating logs like:

dbug: Microsoft.Extensions.Localization.ResourceManagerStringLocalizer[1]
      ResourceManagerStringLocalizer searched for 'Welcome' in 'BlazorApp1.Resources.Pages.Index' with culture 'en'.
dbug: Microsoft.Extensions.Localization.ResourceManagerStringLocalizer[1]
      ResourceManagerStringLocalizer searched for 'Welcome' in 'BlazorApp1.Resources.Pages.Index' with culture 'de'.

on each request with culture/ui-culture query parameter used in the url.

@TanayParikh
Copy link
Contributor

Potentially related to: #28521

@TanayParikh TanayParikh modified the milestones: Backlog, .NET 7 Planning Oct 18, 2021
@ghost
Copy link

ghost commented Oct 21, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@rafael-f
Copy link

rafael-f commented Jul 25, 2022

I don't know why, but after I modified my Pages/_Hosts.cshtml file to contain:

this.HttpContext.Response.Cookies.Append(

        CookieRequestCultureProvider.DefaultCookieName,
        
        CookieRequestCultureProvider.MakeCookieValue(
        
            new RequestCulture(
            
                CultureInfo.CurrentCulture,
                
                CultureInfo.CurrentUICulture)));

The querystring started to work...

(Sorry but I don't know how to format code on github comments..., mine never works)

@dotnet dotnet deleted a comment Nov 12, 2023
@hishamco
Copy link
Member

hishamco commented May 7, 2024

AFAIK the QueryStringRequestCultureProvider works well with the Blazor Server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-server feature-localization severity-major This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests