Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4138

Blazor server localization after login using ClaimType locale not working

$
0
0

We are using Blazor Server and we have the localization up and running, but we are running into an issue when we want to use the users account defined locale. e.g. the workstation is configured on en-US but the user is a temp employee using CZ or NL language. So the users database account has locale nl-NL for example.

So initialization for the localization is:

var localizeOptions = new RequestLocalizationOptions()    .SetDefaultCulture("en-US")    .AddSupportedCultures(new[] { "en-US", "nl-NL", "be-NL" })    .AddSupportedUICultures(new[] { "en-US", "nl-NL", "be-NL" })    .AddInitialRequestCultureProvider((new CustomRequestCultureProvider(async context =>    {      var cultureClaim = context.User.Claims.Where(x => x.Type == ClaimTypes.Locality).FirstOrDefault();      var result = new ProviderCultureResult(cultureClaim?.Value ?? "en-US");      Console.WriteLine($"Haay: {string.Join(',', context.User.Claims.Select(x => x.Value).ToList())}");      return await Task.FromResult(result);    })));app.UseRequestLocalization(localizeOptions);

And the localization is working fine, but the part with the AddInitialRequestCultureProvider is not. The user context is null here. The user has not been initialized.

When I debug I also see that the AuthenticationStateProvider is called after the AddInitialRequestCultureProvider is called.

So I am a bit at a dead end here, can't really find others that are running into the same. I hope some of you might have another insight here.

The application is only accessible after a login, so maybe there is something possible there. After login -> set cookie or something like that, but I can't access the Response in the codebehind after pressing the login button.

With regards,

Wesley.


Viewing all articles
Browse latest Browse all 4138

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>