Copied to clipboard

Flag this post as spam?

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


  • Jennifer Killingsworth 191 posts 248 karma points
    Jul 18, 2016 @ 14:38
    Jennifer Killingsworth
    0

    51Degrees.Mobi - Umbraco 4.11.10

    I'm in the process of upgrading our Umbraco instance in an effort to get it to a recent version of Umbraco 7. I successfully upgraded from 4.7.1.1. to 4.8.1 with everything working fine. My latest upgrade (in a dev environment) to 4.11.10 has caused the Mobile version of our site to stop working.

    We have mobile templates for each of our desktop templates named Mobilexxx.master

    The version that was working is version is 51Degrees.Mobi 4.0.4.1

    The 51Degrees.mobi.config file in the App_Data folder:

    <configSections>        
    <sectionGroup name="fiftyOne">          
    <section name="log" type="FiftyOne.Foundation.Mobile.Configuration.LogSection, FiftyOne.Foundation" requirePermission="false" allowDefinition="Everywhere" restartOnExternalChanges="false" allowExeDefinition="MachineToApplication"/>             
    <section name="redirect" type="FiftyOne.Foundation.Mobile.Configuration.RedirectSection, FiftyOne.Foundation" requirePermission="false" allowDefinition="Everywhere" restartOnExternalChanges="false" allowExeDefinition="MachineToApplication"/>           
    <section name="detection" type="FiftyOne.Foundation.Mobile.Detection.Configuration.DetectionSection, FiftyOne.Foundation" requirePermission="false" allowDefinition="Everywhere" restartOnExternalChanges="false" allowExeDefinition="MachineToApplication"/>           
    <section name="wurfl" type="FiftyOne.Foundation.Mobile.Detection.Wurfl.Configuration.WurflSection, FiftyOne.Foundation" requirePermission="false" allowDefinition="Everywhere" restartOnExternalChanges="false" allowExeDefinition="MachineToApplication"/>         
    </sectionGroup>
      </configSections> 
        <fiftyOne>      
    <redirect timeout="20" firstRequestOnly="true" mobilePagesRegex="^\w+://m.myfwc.com/">          
        <locations>
        <location name="noredirect" url="">
            <add property="Url" matchExpression="[&amp;|\?]noredirect"/>
        </location>
        <location name="tablet" url="http://m.myfwc.com/{0}" matchExpression="(?&lt;=^\w+://.+/)(.*)">
            <add property="IsTablet" matchExpression="true"/>
            <add property="IsMobile" matchExpression="true"/>
        </location>
        <location name="mobile" url="http://m.myfwc.com/{0}" matchExpression="(?&lt;=^\w+://.+/)(.*)">
            <add property="IsMobile" matchExpression="true"/>
        </location>     
        </locations>        
    </redirect>
    
            <log logFile="~/App_Data/51Degrees.mobi/Log.txt" logLevel="Info"/>      
    <detection binaryFilePath="~/App_Data/51Degrees.mobi/51Degrees.mobi-Lite-2012.07.31.dat" />
        <wurfl wurflFilePath="~/App_Data/51Degrees.mobi/wurfl-2.3.2.xml.gz" newDeviceDetail="maximum"  newDevicesURL="" useActualDeviceRoot="false">
          <wurflPatches>
            <add name="browser_definitions" filePath="~/App_Data/51Degrees.mobi/web_browsers_patch.xml" enabled="true"/>
          </wurflPatches>
        </wurfl>    
    </fiftyOne>
    

    And here's a switchMobile.cs in the App_Code folder:

    using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Web; using umbraco.BusinessLogic; using umbraco.cms.businesslogic.web; using umbraco.NodeFactory; using umbraco;
    
    namespace Level2.Events {
        public class TEMP_changeTemplateToMobile : ApplicationBase
        {
    
            public TEMP_changeTemplateToMobile()
            {
                UmbracoDefault.BeforeRequestInit += new UmbracoDefault.RequestInitEventHandler(UmbracoDefault_BeforeRequestInit);
            }
            void UmbracoDefault_BeforeRequestInit(object sender, RequestInitEventArgs e)
            {
                var page = (UmbracoDefault)sender;          var doc = new Document(e.PageId);
                            HttpContext.Current.Trace.Write("changeTemplateToMobile.url",HttpContext.Current.Request.Url.Authority);            if (HttpContext.Current.Request.Url.Authority.StartsWith("m."))
                    {
                    // check if template exists and if it does, show the mobile
                    string mobTemplate = page.MasterPageFile.Insert(page.MasterPageFile.LastIndexOf("/") + 1, "Mobile");
                    string mobPath = HttpContext.Current.Server.MapPath(mobTemplate);
                    HttpContext.Current.Trace.Write("changeTemplateToMobile.template",page.MasterPageFile);
                    HttpContext.Current.Trace.Write("changeTemplateToMobile.new_template",mobTemplate);
    
                    if(File.Exists(mobPath) && doc.getProperty("isMobile").Value.Equals(1))
                    {
                        HttpContext.Current.Trace.Write("changeTemplateToMobile.switching","true");
                        page.MasterPageFile = mobTemplate;
                    }   
                }
            }
        } }
    

    Since the old version of 51Degrees.mobi didn't work at all, I upgraded 51Degrees.mobi to version 2.1.21.4. I believe I have the 51Degrees.mobi.config set up correctly, but it appears I have to make changes to the switchMobile.cs because I'm getting this error:

    Server Error in '/' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
    
    Source Error:
    
    
    Line 27:                { 
    Line 28:                // check if template exists and if it does, show the mobile 
    Line 29:                string mobTemplate = page.MasterPageFile.Insert(page.MasterPageFile.LastIndexOf("/") + 1, "Mobile"); 
    Line 30:                string mobPath = HttpContext.Current.Server.MapPath(mobTemplate); 
    Line 31:
                    HttpContext.Current.Trace.Write("changeTemplateToMobile.template",page.MasterPageFile);
    
    
    Source File: e:\wwwroot\App_Code\switchMobile.cs    Line: 29
    
    Stack Trace:
    
    
    [NullReferenceException: Object reference not set to an instance of an object.]    Level2.Events.TEMP_changeTemplateToMobile.UmbracoDefault_BeforeRequestInit(Object sender, RequestInitEventArgs e) in e:\wwwroot\App_Code\switchMobile.cs:29    umbraco.UmbracoDefault.FireBeforeRequestInit(RequestInitEventArgs e)
    +22    umbraco.UmbracoDefault.OnPreInit(EventArgs e) +276    System.Web.UI.Page.PerformPreInit() +31    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    +335
    

    We had a contractor originally set this up for us. Any thoughts on how to fix?

  • Jennifer Killingsworth 191 posts 248 karma points
    Jul 19, 2016 @ 15:00
    Jennifer Killingsworth
    0

    Can anyone assist?

  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Jul 20, 2016 @ 16:13
    Ravi Motha
    0

    Hi I just want to confirm aht the error and issue is, is it when recognising a mobile request attempting to get the the mobile template//

    and that is coming back as null

  • Jennifer Killingsworth 191 posts 248 karma points
    Jul 20, 2016 @ 16:40
    Jennifer Killingsworth
    0

    I would assume so given that is what the error message says, is there some way I can verify that it's receiving a null?

    BTW, I didn't make any changes to the switchMobile.cs file. It was written by a contractor and has worked all the way through Umbraco 4.8.1.

    Did Umbraco change the way it handles Master Pages in 4.11.10?

  • Thomas Morris 35 posts 133 karma points MVP 2x c-trib
    Jul 21, 2016 @ 08:46
    Thomas Morris
    0

    MVC was introduced Umbraco 4.10, which may have an affect on this. http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410/

    Likewise, some of the events or services being used might have changed.

    This line is failing:

    string mobTemplate = page.MasterPageFile.Insert(page.MasterPageFile.LastIndexOf("/") + 1, "Mobile"); 
    

    So, something within that line is being returned as null and the code is trying to access properties which it can't. Other than doing some checks for that within the code, you'll likely need to move further up the chain to understand why the thing which you are trying to code against is null.

    My guess is that either the page object is null or the reference to page.MasterPageFile is null

  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Jul 21, 2016 @ 09:10
    Ravi Motha
    0

    It may also be that there may be no LastindexOf("/") and that is giving you a false starting point.

    I'd look at tepping through the code and seeing what value page.MasterPageFile is giving you and seeing if there is a "/" when it is being evaluated

  • Jennifer Killingsworth 191 posts 248 karma points
    Jul 21, 2016 @ 14:53
    Jennifer Killingsworth
    0

    I"m not a .Net developer. We had this done for us by a contractor. Sometimes I can figure out how to manipulate the code on my own and other times not so much.

    I'll look through the Umbraco documentation and see what I can find regarding page and page.MasterPageFile.

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft