如题,主要是区分手机和电脑,怎么在后台程序里知道用户是用手机打开网站还是用电脑打开网站呢?

解决方案 »

  1.   

    判断Agent
    public static bool GetClientWeb()
        {
            bool result = false;
            string clientType = string.Concat(HttpContext.Current.Request.UserAgent);
            if (clientType.ToLower().Contains("mozilla") || clientType.ToLower().Contains("opera"))
            {
                result = true;
            }
            return result;
        }
      

  2.   

    楼上正解http协议每次都会把用户设备和浏览器信息发送给服务端例如:
    User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; QQDownload 715; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)
      

  3.   

    分析HttpContext.Current.Request.UserAgent  
      

  4.   

    HttpContext.Current.Request.UserAgent这句就行了