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:
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?
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
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.
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:
And here's a switchMobile.cs in the App_Code folder:
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:
We had a contractor originally set this up for us. Any thoughts on how to fix?
Can anyone assist?
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
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?
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:
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 topage.MasterPageFile
is nullIt 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
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!
is working on a reply...