{"id":1345,"date":"2021-05-16T00:42:45","date_gmt":"2021-05-15T23:42:45","guid":{"rendered":"https:\/\/coding.moris.org\/?p=1345"},"modified":"2021-05-29T17:49:49","modified_gmt":"2021-05-29T16:49:49","slug":"caveat-with-addinitialrequestcultureprovider-in-asp-net-core","status":"publish","type":"post","link":"https:\/\/priscimon.net\/coding\/2021\/05\/16\/caveat-with-addinitialrequestcultureprovider-in-asp-net-core\/","title":{"rendered":"Caveat with AddInitialRequestCultureProvider()  in ASP.NET Core"},"content":{"rendered":"\n<p> <code>AddInitialRequestCultureProvider()<\/code> in ASP.NET Core localisation seems to have an undefined behaviour when it is used in both services and application builder configurations to add a custom  <code>RequestCultureProvider<\/code>.<\/p>\n\n\n\n<p>If you want to use a custom <code>RequestCultureProvider<\/code> to customise how the applicable culture is determined for an incoming HTTP request (for example, by looking up the chosen culture of a user in the database), you must configure the provider in the <em>services <\/em>collection as described in the section <a href=\"https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/fundamentals\/localization?view=aspnetcore-5.0#use-a-custom-provider-2\">&#8216;Use a custom provider&#8217;<\/a>.<\/p>\n\n\n\n<p>You <strong>must <\/strong>also call <code>IApplicationBuilder.UseRequestLocalization()<\/code>, but you <strong>must not <\/strong>pass any argument to the method.<code> <\/code>If a  <code>RequestLocalizationOptions<\/code> argument is specified here, it supersedes what is configured in the services collection, and your custom <code>RequestCultureProvider<\/code> does not work.<\/p>\n\n\n\n<p>Typically, you configure the middleware in the application builder before the services. But in order to emphasise the significance of setting the localisation options only in the services configuration, I have reversed this order on purpose.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>AddInitialRequestCultureProvider() in ASP.NET Core localisation seems to have an undefined behaviour when it is used in both services and application builder configurations to add a custom RequestCultureProvider. If you want to use a custom RequestCultureProvider to customise how the applicable culture is determined for an incoming HTTP request (for example, by looking up the chosen [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1345","post","type-post","status-publish","format-standard","hentry","category-general"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3I4g9-lH","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/posts\/1345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/comments?post=1345"}],"version-history":[{"count":40,"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/posts\/1345\/revisions"}],"predecessor-version":[{"id":1389,"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/posts\/1345\/revisions\/1389"}],"wp:attachment":[{"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/media?parent=1345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/categories?post=1345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/tags?post=1345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}