Setting Culture for ASP.NET MVC application on VS dev server and IIS

后端 未结 4 1495
一整个雨季
一整个雨季 2020-11-30 00:41

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

In the Application_BeginRequest()

相关标签:
4条回答
  • 2020-11-30 00:54

    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");
    
    0 讨论(0)
  • 2020-11-30 00:55

    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.

    0 讨论(0)
  • 2020-11-30 01:02

    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");
    
                 }
    
    0 讨论(0)
  • 2020-11-30 01:06

    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

    0 讨论(0)
提交回复
热议问题