![](/img/trans.png)
[英]Install ASP.NET 5.0 version of System.ServiceModel.Syndication
[英]How to get operating system version asp.net
我想获得浏览器打开的操作系统版本,实际上我的项目是一个asp.net项目,我想知道哪个操作系统在客户端上运行但是有一个问题。 因为客户端将使用xp,但同时将使用Windows CE 5.0,因此Windows CE中的Internet Explorer不如xp中的那个好,因为它会将用户重定向到我为之设计的页面Windows CE。 那么有任何解决方案吗?
谢谢..
使用Request.UserAgent
- 这可能会提供您需要的所有信息。
有一个“用户代理列表”网站提供了大量的示例字符串,但如果您的客户端设置范围有限,那么只需尝试每个设置并记录用户代理作为初步步骤。
请注意,许多浏览器将允许您“欺骗”用户代理字符串,因此您不得将其用于安全目的 - 但听起来好像您的用例非常合理。
它的要点是使用Request.Browser.Platform
,版本在Request.UserAgent
。
由于所选答案不是最新的并且提供了断开的链接,我决定发布我完成它的方式:
我安装了一个很酷的工具: https : //github.com/ua-parser/uap-csharp
将用户代理解析为OS,浏览器,浏览器版本等...
链接到Nuget 。
这是如何使用它:
public static string GetUserBrowser(string userAgent)
{
// get a parser with the embedded regex patterns
var uaParser = Parser.GetDefault();
ClientInfo c = uaParser.Parse(userAgent);
return c.UserAgent.Family;
}
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;
}
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
}
USER_AGENT
参数(在请求参数上)应该讲述故事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.