Multi-lingual web application - how do I detect the user's language in ASP.NET?

后端 未结 6 802
说谎
说谎 2020-12-15 05:20

I\'m building an ASP.NET web application, and all of my strings are stored in a resource file. I\'d like to add a second language to my application, and ideally, I\'d like t

6条回答
  •  一整个雨季
    2020-12-15 05:58

    This is a great question, as localization in ASP.NET is overlooked by many developers.

    ASP.NET should automatically pick up on the user's browser settings and force the CultureInfo.CurrentCulture to the user's browser language. You can force the issue with a line in Page_OnInit() like:

    Thread.CurrentThread.CurrentCulture = new CultureInfo(HttpContext.Current.Request.UserLanguages[0]);
    

    How can you test this? Enter the languages panel on our browser and change settings.

提交回复
热议问题