C# 獲取客戶端資訊 /asp.net/WebService/WebForm

kingboy發表於2013-08-18

Request.Browser.MajorVersion.ToString();//獲取客戶端瀏覽器的(主)版本號
Request.Browser.Version.ToString();   //獲取客戶端瀏覽器的完整版本號
Request.Browser.Platform.ToString();  //獲取客戶端使用平臺的名字
Request.UserHostAddress.ToString();   //獲取遠端客戶端主機IP
HttpRequest.Url.ToString();           //獲取有關當前請求的URL的資訊。  
HttpRequest.UrlReferrer.ToString();   //獲取有關客戶端上次請求的URL的資訊,該請求連結到當前的    URL。  
HttpRequest.UserAgent.ToString();       //獲取客戶端瀏覽器的原始使用者代理資訊。  
HttpRequest.UserHostAddress.ToString(); //獲取遠端客戶端的IP主機地址。  
HttpRequest.UserHostName.ToString();    //獲取遠端客戶端的DNS名稱。  
HttpRequest.UserLanguages.ToString();   //獲取客戶端語言首選項的排序字串陣列。
 
 
 
System.Web.HttpBrowserCapabilities browser = Request.Browser;
    string s = "Browser Capabilities\n"
       + "Type = "                     + browser.Type + "\n"
       + "Name = "                     + browser.Browser + "\n"
       + "Version = "                  + browser.Version + "\n"
       + "Major Version = "            + browser.MajorVersion + "\n"
       + "Minor Version = "            + browser.MinorVersion + "\n"
       + "Platform = "                 + browser.Platform + "\n"
       + "Is Beta = "                  + browser.Beta + "\n"
       + "Is Crawler = "               + browser.Crawler + "\n"
       + "Is AOL = "                   + browser.AOL + "\n"
       + "Is Win16 = "                 + browser.Win16 + "\n"
       + "Is Win32 = "                 + browser.Win32 + "\n"
       + "Supports Frames = "          + browser.Frames + "\n"
       + "Supports Tables = "          + browser.Tables + "\n"
       + "Supports Cookies = "         + browser.Cookies + "\n"
       + "Supports VBScript = "        + browser.VBScript + "\n"
       + "Supports JavaScript = "      + browser.JavaScript + "\n"
       + "Supports Java Applets = "    + browser.JavaApplets + "\n"
       + "Supports ActiveX Controls = " + browser.ActiveXControls + "\n";
    TextBox1.Text = s;
 
//////////////////////////////////////////////////////////////////////////////////////
在.NET中,WebService和WebForm頁面
 
Web Service使用(通過HttpContext物件呼叫Request物件):
HttpContext.Current.Request.UserHostAddress
HttpContext.Current.Request.ServerVariables.GetValues("REMOTE_ADDR")[0]
Web Form使用(可直接使用Request物件):
Request.ServerVariables.GetValues("REMOTE_ADDR")[0]
HttpContext.Current.Request.UserHostAddress

相關文章