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

我有以下代码获取用户的详细信息:
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
}

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....