ASP.NET Development Server ignoring Browser Culture
-
23-08-2019 - |
Question
I'm trying to implement a simple example of where ASP.NET changes culture. I'm running Windows 7, IE 8, and VS 2008. My Label looks like this:
<asp:Label ID="TextBox1" runat="server" meta:resourcekey="Greeting"></asp:Label>
I have two files in App_LocalResources: Default.aspx.resx and Default.aspx.fr.resx.
In them, I have a string value called "Greeting.Text" and the value is set to "Hello!" in one page, and "Bonjour!" in the other.
I have my browser set to prefer fr-FR as the default language. When I open the page using the ASP.NET Development Server through F5 or Shift-F5, the page is apparently recognizing my culture as en-US, regardless of what I set in the Languages dialog for the browser.
That being said, the browser is configured correctly, as Google shows up in French.
When I add a label to the page and set the Text of the label to the CurrentCulture or CurrentUICulture's name, I get en-US, which is obviously not what I had entered.
Does anybody have any idea why this isn't working properly?
Solution
ASP.NET does not automatically change culture based on the browser by default. Add this to your web.config:
<configuration>
<system.web>
<globalization culture="auto"
enableBestFitResponseEncoding="false"
fileEncoding="utf-8"
requestEncoding="utf-8"
responseEncoding="utf-8"
responseHeaderEncoding="utf-8"
uiCulture="auto"/>
</system.web>
</configuration>
Note, the culture="auto"
and uiCulture="auto"
are the important bits for what you are looking for, although the rest is probably a good idea as well. Also note, the enableClientBasedCulture attribute you may see in the documentation is not used by ASP.NET at the current time.