zoukankan      html  css  js  c++  java
  • .net判断用户使用的是移动设备还是PC

    using System.Text.RegularExpressions;//头部引入正则的命名空间
    //为了加强准确性,防止支持wap的浏览器如opera,加入操作系统验证。openwave|后为pc操作系统
    string osPat = "mozilla|m3gate|winwap|openwave|Windows NT|Windows 3.1|95|Blackcomb|98|ME|X Window|Longhorn|ubuntu|AIX|Linux|AmigaOS|BEOS|HP-UX|OpenBSD|FreeBSD|NetBSD|OS/2|OSF1|SUN";
    string uAgent = Request.ServerVariables["HTTP_USER_AGENT"];
    Regex reg = new Regex(osPat);
    if (reg.IsMatch(uAgent))
    {
    Response.Write("电脑访问");
    }
    else
    {
    Response.Write("手机访问");
    }
    Response.Write("<br/>" + uAgent);
  • 相关阅读:
    索引
    convert 时间转换
    SQL中的case when then else end用法
    SVN安装图解
    dos 命令
    阿里云服务器相关知识
    mvc知识应用
    MVC分页
    mvc系统过滤器
    .net 接口
  • 原文地址:https://www.cnblogs.com/wwy224y/p/4730623.html
Copyright © 2011-2022 走看看