how do I detect user operating system

前端 未结 11 919
难免孤独
难免孤独 2020-12-01 03:58

I have the following code to obtain user details:

HttpBrowserCapabilities bc = HttpContext.Current.Request.Browser;
string UserAgent = HttpContext.Current.Re         


        
11条回答
  •  爱一瞬间的悲伤
    2020-12-01 04:11

    private string getOS()
    {
        string os = null;
        if (Request.UserAgent.IndexOf("Windows NT 5.1") > 0)
        {
            os ="Windows XP";
            return os;
        }
        else if (Request.UserAgent.IndexOf("Windows NT 6.0") > 0)
        {
            os= "Windows Vista";
            return os;
        }
        else if (Request.UserAgent.IndexOf("Windows NT 6.1") > 0)
        {
            os = "Windows 7";
            return os;
        }
        else if (Request.UserAgent.IndexOf("Intel Mac OS X") > 0)
        {
            //os = "Mac OS or older version of Windows";
            os = "Intel Mac OS X";
            return os;
        }
        else
        {
            os = "You are using older version of Windows or Mac OS";
            return os;
        }
    
    }
    

提交回复
热议问题