我有以下代码来获取用户的详细信息:
HttpBrowserCapabilities bc = HttpContext.Current.Request.Browser; string UserAgent = HttpContext.Current.Request.UserAgent; ENT_TrackingData ret = new ENT_TrackingData() { IPAddress = HttpContext.Current.Request.UserHostAddress,Browser = bc.Browser + " " + bc.Version,DateStamp = DateTime.Now,PageViewed = HttpContext.Current.Request.Url.AbsolutePath,NodeId = UmbracoHelper.GetCurrentNodeID(),IsMobileDevice = IsMobileDevice(UserAgent),Platform = bc.Platform };
这很好,但我注意到,平台总是说Windows NT为我的机器而不是Windows 7.有没有办法在ASP.Net中检测这种类型的信息?
解决方法
使用
Request.UserAgent
if (Request.UserAgent.IndexOf("Windows NT 5.1") > 0) { //xp } else if (Request.UserAgent.IndexOf("Windows NT 6.0") > 0) { //VISTA } else if (Request.UserAgent.IndexOf("Windows NT 6.1") > 0) { //7 } else if (Request.UserAgent.IndexOf("Windows NT 6.2") > 0) { //8 } else if (Request.UserAgent.IndexOf("Windows NT 6.3") > 0) { //8.1 } else if (Request.UserAgent.IndexOf("Windows NT 10.0") > 0) { //10 }