加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 如何检测用户操作系统

发布时间:2020-12-15 23:44:07 所属栏目:asp.Net 来源:网络整理
导读:我有以下代码来获取用户的详细信息: HttpBrowserCapabilities bc = HttpContext.Current.Request.Browser;string UserAgent = HttpContext.Current.Request.UserAgent;ENT_TrackingData ret = new ENT_TrackingData(){ IPAddress = HttpContext.Current.Req
我有以下代码来获取用户的详细信息:
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
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读