C# 获取客户机&x27;s操作系统';姓名
我想获取客户端操作系统的名称(即Windows XP、Windows 7、Windows Vista)。使用C# 获取客户机&x27;s操作系统';姓名,c#,.net,asp.net,C#,.net,Asp.net,我想获取客户端操作系统的名称(即Windows XP、Windows 7、Windows Vista)。使用Request.Browser.Platform,版本在Request.UserAgent HttpBrowserCapabilities browse = Request.Browser; string platform = browse.Platform; 您还可以在用户代理的帮助下找到 String userAgent = Request.UserAgent;
Request.Browser.Platform
,版本在Request.UserAgent
HttpBrowserCapabilities browse = Request.Browser;
string platform = browse.Platform;
您还可以在用户代理的帮助下找到
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
}
我安装了一个名为:
的很酷的工具,可以将用户代理解析为操作系统、浏览器、浏览器版本等。
这就是它的使用方式:
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;
}
我相信这会在XP、Vista和7上产生
WinNT
。不是很有用。最好使用下面提到的nuget UAParser。@abatishchev the Request.UserAgent给了我“Mozilla/5.0(兼容;MSIE 9.0;Windows NT 6.1;WOW64;Trident/5.0)”@aaa:实际上这是Tejo的答案。Windows 6.1表示Windows 7或Windows Server 2008 R2感谢您提供的信息。Windows 6.1表示Windows 7或Windows Server 2008 R2。@Waqas提供的链接帮助我解决了我的问题。请阅读下面我的答案以获得最新的解决方案。
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;
}