33

I need to fix CurrentCulture as the invariant culture in an ASP.NET application. How can I do this?

<configuration>
   <system.web>
      <globalization culture="???" />
   ...

2 Answers 2

45

Either add the following to your web.config file:

<system.web>
    <globalization culture="en-US" uiCulture="en-US" />
</system.web>

or you can add this statement on the page:

<%@ Page uiCulture="en-US" culture="en-US" %>

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Why is this upvoted 30 times? This isn't the invariant culture, it's the en-US culture, which is not the invariant culture.
@RobIII, i would guess that's because they "know" there is no other culture. So, for them, the "en-US", is an invariant culture. Or maybe it's a comment on how the "en-US" culture doesn't and will not ever change or evolve in any way, shape of form.
28

According to the CultureInfo class documentation, an empty string specifies InvariantCulture.

Edit (tested on .NET 3.5 sp1)
By default, Culture and UICulture are set to "" in the web.config. I guess .Net just does its own thing though, and sets them to "en-US" at run time, even though the documentation says that "en" is the invariant culture, not "en-US".

The @Page directive could be interfering with you. If you used the "Generate Local Resources" tool of the page designer, it automatically adds culture="auto" uiculture="auto" to your page directive, which overrides the web.config. If you just delete those and someone uses that tool later, whammo, they come back, set to auto, bugging up your application. If you try to set them to "", you get an error.

Try setting both the web.config and page directive to this and hope for the best?

culture="en-US" uiCulture="en"

3 Comments

See my updates. I wish you the best of luck. Hopefully someone with working knowledge of the internals can help out more with this.
This is not answer, but this is something that I ended with. Thanks.
ASP.NET get machine default language. In my thread the Culture is pt-BR

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.