zoukankan      html  css  js  c++  java
  • 在.Net里取得浏览器客户端的语言区域信息

    用这个可以取到用户的语言区域,
            strCulture = System.Threading.Thread.CurrentThread.CurrentUICulture.ToString();
            if(strCulture == "zh-TW")
            {
               LangID = "ChineseBG18030";
            }
            else if(strCulture == "zh-CN")
            {
               LangID = "Chinese(GB2312)";
            }
            else
            {
               LangID = "English";
            }

    但要在 Global.asax.cs里增加一段代码才可以不然就不行。
                    protected void Application_BeginRequest(Object sender, EventArgs e)
                    {
                            //为当前用户配置Culture
                            string strLang = "zh-cn";
                            if(this.Request.UserLanguages != null && this.Request.UserLanguages.Length>0)
                                    strLang = Request.UserLanguages[0];
                            System.Globalization.CultureInfo culture=new System.Globalization.CultureInfo(strLang);
                            System.Threading.Thread t=System.Threading.Thread.CurrentThread;
                            try
                            {
                                    t.CurrentUICulture=culture;//这个决定ResourceManager读取资源的行为
                            }
                            catch
                            {}
                           
                    }

  • 相关阅读:
    【习题 8-9 1613】 K-Graph Oddity
    【习题 8-8 UVA
    【Hello 2018 D】Too Easy Problems
    【Hello 2018 C】Party Lemonade
    【Hello 2018 B】Christmas Spruce
    【Hello 2018 A】 Modular Exponentiation
    【习题 8-7 UVA
    【习题 8-6 UVA
    【习题 8-4 UVA
    【习题 8-3 UVA
  • 原文地址:https://www.cnblogs.com/liubiqu/p/181104.html
Copyright © 2011-2022 走看看