“Asp.net”和“Silverlight”并存和切换。Asp.net和Silverlight并存的Web应用程序。“Asp.net”,在用户用移动设备打开的时候采用。   移动浏览器对"JS"的解释还是存在这样和那样的问题。“Silverlight”,在用户用“PC”的时候采用。怎样写可以实现这样的页面跳转?   如果用户用的是“PC”就跳转到Silverlight页面,用的是移动设备就跳转到“Asp.net”页面。        Web程序可不可以识别是“PC”,还是“移动设备”?     还是只能识别有没有安装“Silverlight”应用程序。有没有这样的实例可以参考???

解决方案 »

  1.   

    根据useragent判断客户端系统和浏览器。
      

  2.   

    没找到100%准确的方案,不过CSDN里也有人发类似的问题,Lz可以参考一下
    http://topic.csdn.net/u/20100624/11/03c1a397-da01-41a4-9e61-34e19f8976fc.html
      

  3.   

    HTTP_ACCEPT
    HTTP_USER_AGENT
    PC一般都有自己的关键字,例如:MSIE,Opera,gecko
    HTTP_UA_OS
    MOBILE里的智能手机一般有这个变量
     string clientType = string.Concat(HttpContext.Current.Request.UserAgent);
      if (clientType.ToLower().Contains("mozilla") || clientType.ToLower().Contains("opera"))
      {
        
      }
      

  4.   

    浏览器+操作系统验证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);
      

  5.   


    大师,这种方法。手机Android  的操作系统判断不出来啊,它认为“Android  操作系统”为“PC”操作系统。怎么办???
      

  6.   

    string uAgent = Request.ServerVariables["HTTP_USER_AGENT"];

    "Android   UC"浏览器:JUC(Linux;U;2.3.4;zh-cn;GT-S5830;320*480)  UCWeb7.9.3.103/139/999“Android 内置”浏览器:
    Mozilla/5.0(Linux;U;Android2.3.4;zh-cn;GF-55830 Building/GIGNERBREAD)  AppleWebKit/533.1(KHTML,like Gecko )version/4.0 Mobile  Safari  533.1
    "Android"操作被认为了“PC”操作系统。
    Windows  Phone 下可以正常跳转。IE9:  Mozilla/5.0(compatible;MSIE 9.0;Windows Phone OS  7.5  ;Trident/5.0;IEMobile/9.0; HTC;HD7  T9292)UC:
    Mozilla/5.0(compatible;MSIE 9.0;Windows Phone OS  7.5  ;Trident/5.0;IEMobile/9.0; HTC;HD7  T9292)
    问题一:“Android”操作系统需要做特殊处理???     还有“UC浏览器”???
    问题二:“Mozilla/5.0”这表示什么???    为什么“移动和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))
                {
                    Label1.Text = "PC:"+uAgent;
                }
                else
                {
                    Label1.Text = "Mobile:"+uAgent;
                }正则表达式,去匹配“Request.ServerVariables["HTTP_USER_AGENT"];”中的所有字符是吗???   “Android”是因为匹配了“Linux”所以被认为是“PC”的对吧???正则表达式是区分大小写的吗???    WindowsPhone移动浏览器也有“Mozilla/5.0”这样的标示,为什么没有匹配出来???