Mobile Detection

Posted by Community Admin on 04-Aug-2018 19:44

Mobile Detection

All Replies

Posted by Community Admin on 27-Sep-2011 00:00

I'm in the process of developing a site where there is a mobile master page, and I need to have the master page switched from the normal master page to the mobile master page on page load when a person access the site using a mobile device.

In the process of investigating different solutions to make this happen, I've studied the following solutions provided on the forum;
http://www.sitefinity.com/devnet/forums/sitefinity-3-x/suggestions/mobile-pc-pda-browsing.aspx
http://www.sitefinity.com/devnet/forums/sitefinity-3-x/designing-with-sitefinity/mobile-friendly-site.aspx
http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/change-master-page-set-page-template-at-runtme.aspx
http://www.sitefinity.com/40/help/developers-guide/how-to-how-to-set-the-theme-of-a-page-at-runtime.html

As well, I've tried installing the SolarMobile theme provided by Sitefinity -- http://www.sitefinity.com/marketplace/themes/solarmobile.aspx

As per the instructions from the solutions I found in the forum, I tried implementing the following code in my main master page...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WURFL;
using Wurfl.AspNet.DeviceBrowser.Helpers;
 
 
public partial class App_Master_DCCC_001 : System.Web.UI.MasterPage
    protected override void OnPreInit(EventArgs e)
    
        base.OnPreInit(e);
 
        bool isMobileDevice;
        try
        
            wurflApi.deviceFileProcessor proc = new wurflApi.deviceFileProcessor(Server.MapPath("/wurfl.xml"));
            wurflApi.capabilitiesGetter api = new wurflApi.capabilitiesGetter(ref proc);
            api.prepareNavigatorModelCapabilities(Request);
            isMobileDevice = bool.Parse(api.getCapability("is_wireless_device"));
        
        catch
        
            isMobileDevice = Request.Browser.IsMobileDevice;
        
 
        if (isMobileDevice)
        
            Page.Theme = "Mobile";
            Page.MasterPageFile = "/App_Master/Mobile.master";
        
     
 
    protected void Page_Load(object sender, EventArgs e)
    
 
    

The first main problem is I can't call "OnPreInit" from the master page, and I'm pretty certain "OnPreInit" must be invoked from a page, and not a master page, but I can't figure out how to run this code on a per page basis.  Most of what I'm reading states to create a custom class.  Maybe I'm a bit dense here, but it really seems I'm having an issue with terminology.  When the phrase "custom class" is being referenced, are they talking about a c# (.cs) class file placed in the App_Code directory?

The other big issue I'm having is using Wurfl.  I'm calling WURFL and Wurfl.AspNet.DeviceBrowser.Helpers with the "using" statement and adding the reference in Visual Studio as directions have suggested, but Visual Studio still throws up the error "The type or namespace name 'wurflApi' could not be found".

Is there an easier way to detect mobile devices or what am I doing wrong here?

Posted by Community Admin on 28-Sep-2011 00:00

When I attempt to implement this solution -- http://www.sitefinity.com/40/help/developers-guide/how-to-how-to-set-the-theme-of-a-page-at-runtime.html -- I receive the following error on the web browser.

Server Error in '/' Application.
 
Compilation Error
 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
 
Compiler Error Message: CS0115: 'CustomRouteHandler.SetPageDirectives(System.Web.UI.Page, Telerik.Sitefinity.Pages.Model.IPageData)': no suitable method found to override
 
Source Error:
 
 
Line 8:  public class CustomRouteHandler : PageRouteHandler
Line 9: 
Line 10:     protected override void SetPageDirectives(Page handler, IPageData pageData)
Line 11:    
Line 12:         base.SetPageDirectives(handler, pageData);
 
Source File: c:\Websites\www.dodgecity.com\App_Code\CustomRouteHandler.cs    Line: 10
 
 
Show Detailed Compiler Output:
 
 
c:\windows\system32\inetsrv> "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /t:library /utf8output /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\e6571f46\e1799ef7_377dcc01\Interop.AccCoreLib.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\c3044aca\00e2ea33_2458cc01\Newtonsoft.Json.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\77d9da9d\715fa52a_387dcc01\WURFL.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\21d6a87d\0063c9a3_9256cc01\Telerik.Sitefinity.Utilities.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\d2a2f6ad\002e262f_2458cc01\Microsoft.WindowsAzure.ServiceRuntime.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\3d7a1be2\0063c9a3_9256cc01\Telerik.Sitefinity.Analytics.Server.DependencyResolution.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\a134d4f5\002e262f_2458cc01\Microsoft.Practices.ServiceLocation.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\8d2b944f\0063c9a3_9256cc01\Telerik.Sitefinity.Resources.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\6c391fde\005b5730_2458cc01\Microsoft.WindowsAzure.StorageClient.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\858cd29a\0063c9a3_9256cc01\Telerik.Web.UI.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\5a6310a9\0063c9a3_9256cc01\Telerik.ReportViewer.WebForms.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\7ac840e1\002e262f_2458cc01\Microsoft.WindowsAzure.Diagnostics.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\b606e711\0063c9a3_9256cc01\Telerik.OpenAccess.35.Extensions.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\154bdfd8\0063c9a3_9256cc01\Telerik.OpenAccess.Web.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\e7b300af\002e262f_2458cc01\Facebook.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Activities.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\43858309\0063c9a3_9256cc01\Telerik.Sitefinity.Model.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\7470cc02\0001f52d_2458cc01\AjaxControlToolkit.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\8fcdb63d\0063c9a3_9256cc01\Telerik.OpenAccess.Config.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\e34f765c\0063c9a3_9256cc01\Telerik.OpenAccess.Runtime.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\209fe420\0001f52d_2458cc01\Interop.DexterLib.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\5aa97755\0063c9a3_9256cc01\Telerik.Sitefinity.Analytics.Server.GoogleAnalyticsPlugin.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\5f1c5508\e1ad1c27_387dcc01\ICSharpCode.SharpZipLib.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\1c0827e8\614f4528_387dcc01\log4net.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\43d8a049\005b5730_2458cc01\mysql.data.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\f669bade\0063c9a3_9256cc01\Telerik.Reporting.OpenXmlRendering.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\ee10f960\0063c9a3_9256cc01\Telerik.OpenAccess.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\9922404c\0063c9a3_9256cc01\Telerik.OpenAccess.MySql.Data.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\67c58234\0063c9a3_9256cc01\Telerik.Windows.RadUploadHandler.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\f8ff78e3\0001f52d_2458cc01\payflow_dotNET.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\3ddde71e\0063c9a3_9256cc01\Telerik.Reporting.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\2f3a8368\0063c9a3_9256cc01\Telerik.Reporting.XpsRendering.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\9f08edb9\0063c9a3_9256cc01\Telerik.Sitefinity.MigrationContracts.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\794fae0c\0063c9a3_9256cc01\Telerik.Sitefinity.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\30e0c79b\002e262f_2458cc01\System.Windows.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\93daa4cf\0063c9a3_9256cc01\Telerik.Sitefinity.Analytics.Server.Infrastructure.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\66ee473e\0001f52d_2458cc01\DirectShowLib-2005.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\7a44ce5a\00e2ea33_2458cc01\Twitterizer2.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\43083bd8\61c4ed28_387dcc01\Wurfl.AspNet.DeviceBrowser.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\a9f740be\0063c9a3_9256cc01\Telerik.Sitefinity.Analytics.Server.Core.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\7efec9d5\005d5380_98d2cb01\NHamcrest.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Routing\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Routing.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\0f2feee7\002e262f_2458cc01\DocumentFormat.OpenXml.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\assembly\dl3\c0241f1c\0063c9a3_9256cc01\Telerik.Web.Design.DLL" /out:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\App_Code.8vils4sh.dll" /debug- /optimize+ /w:4 /nowarn:1659;1699;1701 /warnaserror-  "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\App_Code.8vils4sh.0.cs" "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e7fd84b8\9d9678ed\App_Code.8vils4sh.1.cs"
 
 
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.
 
c:\Websites\www.dodgecity.com\App_Code\CustomRouteHandler.cs(10,29): error CS0115: 'CustomRouteHandler.SetPageDirectives(System.Web.UI.Page, Telerik.Sitefinity.Pages.Model.IPageData)': no suitable method found to override
 
Show Complete Compilation Source:
 
 
Line 1:    using Telerik.Sitefinity.Web;
Line 2:    using System.Web.UI;
Line 3:    using Telerik.Sitefinity.Pages.Model;
Line 4:    using Telerik.Sitefinity.Web.UI;
Line 5:    using Telerik.Sitefinity.Abstractions;
Line 6:    using Telerik.Microsoft.Practices.Unity;
Line 7:   
Line 8:    public class CustomRouteHandler : PageRouteHandler
Line 9:   
Line 10:       protected override void SetPageDirectives(Page handler, IPageData pageData)
Line 11:      
Line 12:           base.SetPageDirectives(handler, pageData);
Line 13:  
Line 14:           var themeName = "SolarMobile";
Line 15:           ThemeController.SetPageTheme(themeName, handler);
Line 16:  
Line 17:      
Line 18:  
Line 19:       public static void RegisterType()
Line 20:      
Line 21:           ObjectFactory.Container.RegisterType<PageRouteHandler, CustomRouteHandler>();
Line 22:      
Line 23:  
 
 
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237

Still lost...

Posted by Community Admin on 29-Sep-2011 00:00

it appears that method is now obsolete, thank you for reporting this, I will alert the documentation team so they can update this article!

according to this thread: http://www.sitefinity.com/devnet/forums/sitefinity-4-x/developing-with-sitefinity/modifing-a-theme-page-at-the-page-init-or-page-load-of-my-master-page.aspx#1742872

the correct method to override is BuildHttpHandler

The thread linked shows an example of changing the theme, but changing the master page should be possible in that method as well...

I hope this is helpful, please let me know if this doesn't solve your issue. thanks!

This thread is closed