[C#] Get the language from a web browser (Get language from access client)
Tag:[C#] [ASP.NET]
ASP.NET Learn how to get the browser's language has been accessed.
The original language of the client access to the HttpRequest object is set to UserLanguage. UserLanguage has become an array, if multiple language support is set UserLanguage multiple languages.

Code Example


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
  public partial class WebForm1 : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (Request.UserLanguages != null) {
        for (int i=0; i<Request.UserLanguages.Length; i++){
          TextBox1.Text += Request.UserLanguages[i] + "\n";
        }
      }
    }
  }
}

Results

Accessed from Japanese OS(Windows 7 Japanese).

ja-JP
Appears in the textbox (TextBox1).

Accessed from English OS(Windows 7 English(US Edition)).

en-US
Appears in the textbox (TextBox1).


Register date :2011-10-20    Last update :2017-01-17
この記事に関連するページ
Tag:[C#] [ASP.NET]
JapaneseEnglish
プライバシー    iPentecについて
iPentec all rights reserverd. (ISDC)