48

This is more specific and cleaner version of this question - Different DateTimeFormat for dev and test environment

In the Application_BeginRequest() method of global.asax.cs in my ASP.NET MVC project there is code:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");

When I set a breakpoint on Controller Action I see the following value of Thread.CurrentThread.CurrentCulture:

  1. In VS dev server - "en-GB"
  2. In IIS - "en-US"

Question is - What settings in IIS are responsible for this and how can I override it?

3
  • possible duplicate of Different DateTimeFormat for dev and test environment Commented Aug 27, 2011 at 17:59
  • I can't immediately see a difference with your previous question. If there is, you should have linked to it and spelled out the difference. Commented Aug 27, 2011 at 18:01
  • I'm new to StackOverflow so please advise me the appropriate way to do it. I've created this question because it's more specific and cleaner than the old one. I've set an update to the old question with a link to the current question. Commented Aug 27, 2011 at 18:17

4 Answers 4

129

Rather than setting the Thread's culture, you can specify it in the web.config like so:

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

That is a more "proper" way of specifying the culture in ASP.NET.

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

3 Comments

@Traumer: in a "new and improved" question you should have mentioned that. Also a complete list of System and Browser language settings for all clients and servers would have been nice.
Thanks for advice. I'll use it in future. But for this question I've already found a solution.
hi, thank you, adding web.config made work my date format, but is it possible to add globalization directly in particular view in mvc this way @using System.Web.WebPages uiCulture="en-GB" culture="en-GB", but date format didn't work, it just shows as text in view, i found this idea here
19

Well, I didn't actually find what IIS setting is responsible, but I've overridden it in Application_PreRequestHandlerExecute() and it finally worked:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");

Comments

6

I think it is a good option to just let the client (i.e. user agent / browser) decide what culture he wants. This can be done by setting the culture and uiCulture attribute of the globalization element in web.config to auto. See "Version 1".

You can also do something like: Take the broswers setting, but if not possbile use en-US as fallback value. See "Version 2".

Version 1:

<configuration>
   <system.web>    
      <globalization culture="auto" uiCulture="auto"/>
   </system.web>
</configuration>

Version 2:

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


See also this article for more info: Auto Detecting and Setting ASP.NET Locale based on Browser Locale

Comments

0

To set a default Culture for your App in MVC, you can easily add this route in your RouteConfig class:

 foreach (var route in routes.Cast<Route>().Where(route =>
 route.GetType() == typeof(MultiLingualRoute)))
             {
                 route.Url = "{language}/" + route.Url;
                 route.Defaults.Add("language", "YOUR-DEFAULT");

             }

Comments

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.