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.
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)
is working on a reply...