首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

如何判断 手机用户和电脑用户登录网站呢

2012-09-17 
怎么判断 手机用户和电脑用户登录网站呢C# codepublic static bool GetClientWeb(){bool result falses

怎么判断 手机用户和电脑用户登录网站呢

C# code
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;  }

刚才测试下返回值都是true

有大虾弄过吗

[解决办法]
C# code
  /// <summary>    /// 判断手机用户UserAgent    /// </summary>    /// <returns></returns>    private bool IsMobile()    {               HttpContext context = HttpContext.Current;        if (context != null)        {            HttpRequest request = context.Request;            if (request.Browser.IsMobileDevice)                return true;            string MobileUserAgent=System.Configuration.ConfigurationManager.AppSettings["MobileUserAgent"];            Regex MOBILE_REGEX = new Regex(MobileUserAgent);            if (string.IsNullOrEmpty(request.UserAgent) || MOBILE_REGEX.IsMatch(request.UserAgent.ToLower()))                return true;                                          }        return false;    }以下为web.config配置里边的<add key="MobileUserAgent" value="iphone|android|nokia|symbian|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile|blackberry|windows ce|motorola|mqqbrowser|ucweb"/> 

热点排行
Bad Request.