首页 > 代码库 > asp.net获取浏览器端操作系统名称

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;
}

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