asp.net获取浏览器端操作系统名称

/// <summary>
/// 获取浏览器端操作系统名称
/// </summary>
/// <returns></returns>
public static string GetOSName()
{
    string osVersion = System.Web.HttpContext.Current.Request.Browser.Platform;
    string userAgent = System.Web.HttpContext.Current.Request.UserAgent;

if (userAgent.Contains("NT 6.2"))
    {
        osVersion = "Windows8/Server 2012";
    }
    if (userAgent.Contains("NT 6.1"))
    {
        osVersion = "Windows7/Server 2008 R2";
    }
    else if (userAgent.Contains("NT 6.0"))
    {
        osVersion = "Windows Vista/Server 2008";
    }
    else if (userAgent.Contains("NT 5.2"))
    {
        osVersion = "Windows Server 2003";
    }
    else if (userAgent.Contains("NT 5.1"))
    {
        osVersion = "WindowsXP";
    }
    else if (userAgent.Contains("NT 5"))
    {
        osVersion = "Windows2000";
    }
    else if (userAgent.Contains("NT 4"))
    {
        osVersion = "WindowsNT4.0";
    }
    else if (userAgent.Contains("Me"))
    {
        osVersion = "WindowsMe";
    }
    else if (userAgent.Contains("98"))
    {
        osVersion = "Windows98";
    }
    else if (userAgent.Contains("95"))
    {
        osVersion = "Windows95";
    }
    else if (userAgent.Contains("Mac"))
    {
        osVersion = "Mac";
    }
    else if (userAgent.Contains("Unix"))
    {
        osVersion = "UNIX";
    }
    else if (userAgent.Contains("Linux"))
    {
        osVersion = "Linux";
    }
    else if (userAgent.Contains("SunOS"))
    {
        osVersion = "SunOS";
    }
    return osVersion;
}

上一篇:POJ 1330 Nearest Common Ancestors(lca)


下一篇:小tips:JS严格模式(use strict)下不能使用arguments.callee的替代方案