在.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
                        {}
                       
                }

posted @ 2005-06-25 17:58  小草  阅读(1130)  评论(0编辑  收藏  举报
Google+