Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mike Chambers 636 posts 1253 karma points c-trib
    Sep 29, 2011 @ 00:39
    Mike Chambers
    0

    mobile/tablet detection with 51degrees.mobi... an alternative approach...

    Just throwing this to the forum to see if anyone can see any gotchas....

    After looking at the 51degrees.mobi approach I wasn't too keen on the redirect approach and the overheads that this causes as well as SEO issues with potential duplicate content issues...

    So thought just use the 51degrees.mobi as the detector, and then override the umbracoDefault to dynamically alter the masterpage at runtime (rather than cause a redirect)

     

     

            protected override void OnPreInit(EventArgs e)
            {
                base.OnPreInit(e);
                try
                {
                    if (String.IsNullOrEmpty(GetCurrentAltTemplateAlias()))
                    {
                        // using the admin specified template
                        Node currentNode = Node.GetCurrent();
                        umbraco.template template = new umbraco.template(currentNode.template);
                       
                        // we're using the http://51degrees.mobi foundation to detect mobile/tablet items.
                        if (Request.Browser.IsMobileDevice == true)
                        {
                            if (Request.Browser["is_tablet"] == "true")
                            {
                                Page.MasterPageFile = Page.MasterPageFile.Replace(".master", "Tablet.master");
                            }
                            else
                            {
                                Page.MasterPageFile = Page.MasterPageFile.Replace(".master", "Mobile.master");
                            }
                            
                        }

                    }
                    else
                    {
                        // already using an alternative template                   
                    }
                }
                catch { }
            }

            public static string GetCurrentAltTemplateAlias()
            {
                return (System.Web.HttpContext.Current.Items["altTemplate"] ?? "").ToString();
            }
    So like I say open to comments on what all and sundry feel about this approach.
    Ta

     

     

Please Sign in or register to post replies

Write your reply to:

Draft