获取客户端的操作系统名称
HttpBrowserCapabilities browse = Request.Browser;
string platform = browse.Platform;
我相信这个结果'WinNT'在XP,Vista和7上不是很有用。 – Bazzz
最好使用下面提到的nuget UAParser。 –
使用Request.Browser.Platform
,并且版本是Request.UserAgent
@abatishchev Request.UserAgent给了我'Mozilla/5.0(compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)' – masif
@aaa:其实这就是Tejo的答案。 Windows 6.1意味着Windows 7或Windows Server 2008 R2 – abatishchev
感谢您的info..Windows 6.1意味着Windows 7或Windows Server 2008 R2。由@Waqas提供的链接帮助我解决了我的问题。 – masif
OperatingSystem os = Environment.OSVersion;
var platform = os.Platform.ToString();
var version = os.Version.ToString();
var servicePack = os.ServicePack.ToString();
您还可以找到与用户代理的帮助。
String userAgent = Request.UserAgent;
if (userAgent.IndexOf("Windows NT 6.3") > 0)
{
//Windows 8.1
}
else if (userAgent.IndexOf("Windows NT 6.2") > 0)
{
//Windows 8
}
else if (userAgent.IndexOf("Windows NT 6.1") > 0)
{
//Windows 7
}
else if (userAgent.IndexOf("Windows NT 6.0") > 0)
{
//Windows Vista
}
else if (userAgent.IndexOf("Windows NT 5.2") > 0)
{
//Windows Server 2003; Windows XP x64 Edition
}
else if (userAgent.IndexOf("Windows NT 5.1") > 0)
{
//Windows XP
}
else if (userAgent.IndexOf("Windows NT 5.01") > 0)
{
//Windows 2000, Service Pack 1 (SP1)
}
else if (userAgent.IndexOf("Windows NT 5.0") > 0)
{
//Windows 2000
}
else if (userAgent.IndexOf("Windows NT 4.0") > 0)
{
//Microsoft Windows NT 4.0
}
else if (userAgent.IndexOf("Win 9x 4.90") > 0)
{
//Windows Millennium Edition (Windows Me)
}
else if (userAgent.IndexOf("Windows 98") > 0)
{
//Windows 98
}
else if (userAgent.IndexOf("Windows 95") > 0)
{
//Windows 95
}
else if (userAgent.IndexOf("Windows CE") > 0)
{
//Windows CE
}
else
{
//Others
}
我安装了一个名为一个很酷的工具:https://github.com/ua-parser/uap-csharp
用来解析用户代理的操作系统,浏览器,浏览器版本等...
Link to Nuget。
这是如何使用它:
public static string GetUserOS(string userAgent)
{
// get a parser with the embedded regex patterns
var uaParser = Parser.GetDefault();
ClientInfo c = uaParser.Parse(userAgent);
return c.OS.Family;
}
阅读下面的最新解决方案我的答案。 –