Detecting Requests from Mobile Browsers in ASP.NET [duplicate]

你离开我真会死。 提交于 2019-11-30 14:29:53

You can use the IsMobileDevice property somewhere in the Request.Browser. You need some decent browser definitions though. I use these excellent set of browser definitions: Ocean's place browser definitions.

They are really in depth and the best I've seen. I think he is currently working on .NET4 ones too.

I think the best solution is WURFL. It is more up date device description repository and it is free. The only inconvenience is .net api is GPL.

Gautam

Keep it simple...

Heres the JS for the same...

Hope it helps someone..

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...")
    }

There is a project on codeplex that you can use : Mobile Device Browser File

Project Description

The Mobile Browser Definition File contains definitions for individual mobile devices and browsers. At run time, ASP.NET uses the information in the request header to determine what type of device/browser has made the request.

This project provides a data file that when used with ASP.NET will detect the incoming mobile device and present you as the web developer with a set of 67 capabilities or properties describing the requesting device. These capabilities range from screen size to cookie support and provide all the information you need to adaptively render content for mobile phones and devices.

What is the Mobile Device Browser Definition File?

The Mobile Device Browser Definition File contains capability definitions for individual mobile devices and browsers. At run time, ASP.NET uses this .browser file, along with the information in the HTTP request header, to determine what type of device/browser has made the request and what the capabilities of that device are. This information is exposed to the developer through the Request.Browser property and allows them to tailor the presentation of their web page to suit the capabilities of the target device.

There's an article on CodeProject which provides such function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!