在 ASP.NET 中检测来自移动浏览器的请求 [英] Detecting Requests from Mobile Browsers in ASP.NET

查看:30
本文介绍了在 ASP.NET 中检测来自移动浏览器的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的网站,我想创建一个更合适的移动版本.例如,主站点使用下拉菜单,我们都知道这在移动设备上是非常失败的.

I have an existing web site and I would like to create a mobile version of it that is more suitable. For instance, the main site uses drop-down menus and we all know those are quite the fail on mobile devices.

如果我检测到来自移动浏览器的请求,我想重定向到我的移动版本(它将是当前站点的子域).因此,当他们通过 Google 搜索某些内容并访问我的网站时,他们会自动看到移动版本(就像维基百科一样).

I would like to redirect to my mobile version (it will be a subdomain of the current site) if I detect a request from a mobile browser. So when they Google something and come to my site, they will automatically see the mobile version (just like Wikipedia).

ASP.NET 是否提供了一种简单的方法来做到这一点?如果没有,我该怎么做?

Does ASP.NET provide an easy way of doing this? If not, how can I do it?

推荐答案

保持简单...

这是相同的 JS...

Heres the JS for the same...

希望对某人有帮助..

var useragent = navigator.userAgent;

var isMobile = !!useragent.match(/iPhone|Android|Blackberry|Sony|Nokia|Motorola|Samsung/i),
    isWebBrowser = !!useragent.match(/Mozilla/i);

// Redirect the call accordingly.

  if(isWebBrowser && !isMobile)
            //call to web portal
            alert(" You seem to me... calling from Web Browser")
    else if(isMobile)
        //call to mobile apps
            alert(" Call seems to be from Mobile device...")
    else
    {
        // jus kiddin...
        alert(" Unable to detect the device..... Please report to admin...")
    }

这篇关于在 ASP.NET 中检测来自移动浏览器的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆