您好,登錄后才能下訂單哦!
怎么在asp.net項目中獲取客戶端的詳細信息?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
實現代碼:
using System; using System.Web; using System.Web.UI; namespace HoverTreeTool.HvtInfo.KeleyiClient { public partial class Index : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string userAgent = Request.UserAgent == null ? "無" : Request.UserAgent; if (!IsPostBack) {lbHoverTreeInfo.Items.Add("您的系統信息為:"); lbHoverTreeInfo.Items.Add("客戶端IP[Page.Request.UserHostAddress]:"+ Page.Request.UserHostAddress); lbHoverTreeInfo.Items.Add("瀏覽器類型[Request.Browser.Browser]:" + Request.Browser.Browser); lbHoverTreeInfo.Items.Add("瀏覽器標識[Request.Browser.Id]:" + Request.Browser.Id); lbHoverTreeInfo.Items.Add("瀏覽器版本號[Request.Browser.Version]:" + Request.Browser.Version); lbHoverTreeInfo.Items.Add("瀏覽器是不是測試版本[Request.Browser.Beta]:" + Request.Browser.Beta); lbHoverTreeInfo.Items.Add("瀏覽器類型[Request.Browser.Type]:" + Request.Browser.Type); lbHoverTreeInfo.Items.Add("是否支持框架網頁[Request.Browser.Frames]:" + Request.Browser.Frames); lbHoverTreeInfo.Items.Add("是否支持Cookie[Request.Browser.Cookies]:" + Request.Browser.Cookies); lbHoverTreeInfo.Items.Add("瀏覽器JScript版本[Request.Browser.JScriptVersion]:" + Request.Browser.JScriptVersion); lbHoverTreeInfo.Items.Add("屏幕分辨率寬[System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width ]]:" + System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width); lbHoverTreeInfo.Items.Add("屏幕分辨率高[System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height ]]:" + System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height); lbHoverTreeInfo.Items.Add("瀏覽器類型[Request.Browser.Type]:" + Request.Browser.Type); lbHoverTreeInfo.Items.Add("客戶端IP[GetHoverTreeIp()]:" + GetHoverTreeIp()); lbHoverTreeInfo.Items.Add("客戶端的操作系統[Request.Browser.Platform]:" + Request.Browser.Platform); lbHoverTreeInfo.Items.Add("客戶端的操作系統[GetHoverTreeOSName(userAgent)]:" + GetHoverTreeOSName(userAgent)); lbHoverTreeInfo.Items.Add("是不是win16系統[Request.Browser.Win16]:" + Request.Browser.Win16); lbHoverTreeInfo.Items.Add("是不是win32系統[Request.Browser.Win32]:" + Request.Browser.Win32); lbHoverTreeInfo.Items.Add("客戶端.NET Framework版本:Request.Browser.ClrVersion]:" + Request.Browser.ClrVersion); lbHoverTreeInfo.Items.Add("是否支持Java[Request.Browser.JavaApplets]:" + Request.Browser.JavaApplets); if (Request.ServerVariables["HTTP_UA_CPU"] == null) lbHoverTreeInfo.Items.Add("CPU 類型[Request.ServerVariables[\"HTTP_UA_CPU\"]]:未知"); else lbHoverTreeInfo.Items.Add("CPU 類型[Request.ServerVariables[\"HTTP_UA_CPU\"]]:" + Request.ServerVariables["HTTP_UA_CPU"]); lbHoverTreeInfo.Items.Add("UserAgent信息[Request.UserAgent]:" + userAgent); lbHoverTreeInfo.Items.Add("By 何問起工具 http://tool.hovertree.com/info/client/"); } } /// <summary> /// 獲取真實IP /// </summary> /// <returns></returns> public string GetHoverTreeIp() { string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (null == result || result == String.Empty) { result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } if (null == result || result == String.Empty) { result = HttpContext.Current.Request.UserHostAddress; } return result; } /// <summary> /// 根據 User Agent 獲取操作系統名稱 /// </summary> private string GetHoverTreeOSName(string userAgent) { string m_hvtOsVersion = "未知"; if (userAgent.Contains("NT 6.4")) { m_hvtOsVersion = "Windows 10"; } else if (userAgent.Contains("NT 6.3")) { m_hvtOsVersion = "Windows 8.1"; } else if (userAgent.Contains("NT 6.2")) { m_hvtOsVersion = "Windows 8"; } else if (userAgent.Contains("NT 6.1")) { m_hvtOsVersion = "Windows 7"; }else if (userAgent.Contains("NT 6.0")) { m_hvtOsVersion = "Windows Vista/Server 2008"; } else if (userAgent.Contains("NT 5.2")) { m_hvtOsVersion = "Windows Server 2003"; } else if (userAgent.Contains("NT 5.1")) { m_hvtOsVersion = "Windows XP"; } else if (userAgent.Contains("NT 5")) { m_hvtOsVersion = "Windows 2000"; } else if (userAgent.Contains("NT 4")) { m_hvtOsVersion = "Windows NT4"; } else if (userAgent.Contains("Me")) { m_hvtOsVersion = "Windows Me"; } else if (userAgent.Contains("98")) { m_hvtOsVersion = "Windows 98"; } else if (userAgent.Contains("95")) { m_hvtOsVersion = "Windows 95"; } else if (userAgent.Contains("Mac")) { m_hvtOsVersion = "Mac"; } else if (userAgent.Contains("Unix")) { m_hvtOsVersion = "UNIX"; } else if (userAgent.Contains("Linux")) { m_hvtOsVersion = "Linux"; } else if (userAgent.Contains("SunOS")) { m_hvtOsVersion = "SunOS"; } return m_hvtOsVersion; } } }
看完上述內容,你們掌握怎么在asp.net項目中獲取客戶端的詳細信息的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。