CurrentCulture incorrectly defaulting to en-US in ASP.net

后端 未结 9 1232
执笔经年
执笔经年 2020-12-08 14:37

I have just migrated around 100 ASP.net sites from IIS 6 on Windows Sever 2003 to IIS 7 on Windows 2008. I\'ve just noticed that various pieces of code that use things like

9条回答
  •  执笔经年
    2020-12-08 14:57

    .Net web application is picking up your browser's default culture. For e.g. in FF, default language is set as shown in below image.

    So, if you want your site's culture other than the one from browser, in page's InitializeCulture method (Create a BasePage and keep below code here and inherit existing pages from this BasePage).

    protected override void InitializeCulture()
        {
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-GB");
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
    
                base.InitializeCulture();
            }
        }
    

提交回复
热议问题