Last post Jun 15, 2015 10:34 AM by malikmeister
Jun 13, 2015 06:26 PM|malikmeister|LINK
I know that asp.net provides code to detect mobile devices, but is there a way to detect tablets vs mobile devices? I don't want the mobile version of my website to be shown if the tablet has a big enough screen, and most tablets do. Right now I have:
Protected Sub Page_PreInit(sender As Object, e As System.EventArgs) Handles Me.PreInit
If IsItMobile() Then
Function IsItMobile() As Boolean
Dim myBrowserCaps As System.Web.HttpBrowserCapabilities = Request.Browser
If (CType(myBrowserCaps, System.Web.Configuration.HttpCapabilitiesBase)).IsMobileDevice Then
Is there any way to make "IsItMobile" return false for tablets such as the iPad, the Samsung galaxy, and windows Surface?
There is also a library produced by 51 degrees, which is an encyclopedia of all types of devices and their sizes, but I'm first looking for a free solution.
Jun 13, 2015 09:20 PM|Rion Williams|LINK
Consider using a Library
You may want to consider taking a look at 51Degree's "Foundation" project (also called the 51Degrees.Mobi project) , which greatly enhances the Mobile detection features available in .NET and is actually recommended by ASP.net as it provides better detection
for more recent devices. You can read more about the Foundation project and download it here as the "Lite" version should still be free for most use-cases :
The reason that I mention this approach is that the built-in detection for mobile devices within ASP.NET can be unreliable or inaccurate and the use of a library like this would strongly improve those features.
You can still access the actual UserAgent string within your server-side code using the
Jun 14, 2015 06:07 AM|malikmeister|LINK
They don't seem to have a way to distinguish between tablets and phones, so I was going to use their function that gets the physical size of the screen instead. But that does not come with the "lite" version.
Jun 14, 2015 02:01 PM|Rion Williams|LINK
Another option might be to consider using something like
WURFL, which is a mobile device database that can help you detect certain information and features about your devices. It also features a client-side option that could be used to help manage your redirection, which is probably going to be the easiest way
to handle this in wurfl.io.
Basically, if you aren't going to be able to access something like 51 Degrees, you'll want to handle this client side. A client-side approach is probably going to be your best option in general as properties like the size of your viewport are going to be
exposed and you can use those to handle if you need to redirect to a mobile site or not.
Jun 15, 2015 10:34 AM|malikmeister|LINK
I found that 51 degrees cloud option does have a free option that does tell you whether you have a tablet or a phone. However the tech person there did tell me the cloud option takes a little more time to load than if the database is on our own server.
Thanks for the help.