Detecting mobile devices

Posted by Community Admin on 03-Aug-2018 19:56

Detecting mobile devices

All Replies

Posted by Community Admin on 05-Oct-2011 00:00

Hi

Is there a way to reliably detect mobile devices in SF so the user could be redirected to a page telling them that mobile devices are not supported?

Thanks

Regards

 

Posted by Community Admin on 07-Oct-2011 00:00

Hi John,

Sitefinity does not support such detection out of the box. I researched a bit with Google and found some useful articles about detecting mobile browsers using ASP.NET

http://www.ytechie.com/2008/10/detecting-mobile-device-user-agents-in-aspnet.html

http://www.codeproject.com/KB/aspnet/mobiledetect.aspx

You could have a landing page and assign a codebehind class to it and perform the check there.

All the best,
Lubomir Velkov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 04-Nov-2011 00:00

Lubomir,
Could you provide me with more information on how I can implement this landing page solution to mobile detection for Sitefinity?

Specifically, I understand the idea of creating a landing page, but what I'm not certain about is is where do I redirect the user to?  Would I just create a page for mobile devices, do I change the default masterpage, or do I create a sub site that shares the same data as the main site?

Very confused. Please help,
Kevin

Posted by Community Admin on 07-Nov-2011 00:00

Hi Kevin,

Well basically your home page is the landing page, so when a user opens you site - e.g. http://mysite.com - the home page will load. Then you assign a code-behind class for this page - a class that inherits from System.Web.UI.Page and in its Page_Load event you do the detection. Then you can use

Server.Transfer()

to redirect the user to a specific branch or subdomain of your site - e.g.

mobile.mysite.com, etc.

I hope this helps.

Regards,
Lubomir Velkov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 24-Nov-2011 00:00

Hi Kevin,

Just to give you some info (you may have found a solution already) we have been building responsive designs with sitefinity and looking at implementing some mobile first items.  We have not been specifically building seperate mobile sites but still needed to identify if a mobile was accessing the site so we could stop the loading of things like banner rotators etc.  We found the .Net IsMobile or whatever the command is to be flaky and we coudnt use server sniffing as we had specific page elements that needed to respond not the site.

We used the 51degrees mobi library which is open source, however we coudn't use it directly in our project as it conflicts with sitefinity (some reason makes the content blocks output as tables) so we had to use a web service implementation where we call and external service, passing in the browser user agent (Based on this, http://51degrees.mobi/Support/Blogs/tabid/212/EntryId/25/Create-Your-Own-NET-Mobile-Detection-Cloud-Service-to-use-with-PHP.aspx it was targetted for PHP but we adjusted it for us, hence the code below).  You simply create a web reference (not a service reference as this doesnt let you send the user agent) and then call it through code like this:

//Setup Service Call
var service = new MobileDetector.Detector();
service.UserAgent = Context.Request.UserAgent;
//Call the service
var result = service.GetCapabilities(new string[] "is_wireless_device", "is_tablet" );
 
//IsMobile Check
if (result[0] != null)
    isMobile = bool.Parse(result[0]);
//IsTablet Check
if (result[1] != null)
    isTablet = bool.Parse(result[1]);
 
if (!isMobile || (isMobile && isTablet))
//Other Code

Hope that helps.

Rob

This thread is closed