
How to keep using MasterPages in Umbraco.
Since some time ago, Umbraco has been moving to use MVC technology and discouraging the use of WebForms and Masterpages, as many developers are moving to this technology too. From version 7.6.0, released in May 2007, Umbraco does not support the editing of WebForms templates from the backoffice.
It makes sense that if we want to keep our solutions up to date with the latest version of Umbraco, we will have to migrate to MVC sooner or later. But what if we cannot, or we (or our clients) don't want to assume that cost? Well, if we want to ensure that all Umbraco funcionalities work properly, then we will have no other choice. Nevertheless, we are still able to keep on using our not so favorite technologies.
MasterPages in an MVC solution
Sebastiaan Janssen has a great blog article explaining how to easily migrate from WebForms to MVC.
In the meantime, there are still a few tricks we can use to keep using WebForms.
This was our case when we were required to upgrade a solution from version 7.4.3 to 7.6.3 (which was the latest release at that time). Considering we had done an upgrade not so long ago, this seemed like an easy task, until we found out the solution was simply not working.
First of all, before explaining anything further, I have to encourage you to always read the general notes as well as the version specific notes on the Our.Umbraco website. They might well save you a headache.
After following the necessary steps, the solution built fine but I received a YSOD and a FileNotFoundException of the type "Could not find file '...\Views\Page.master'".
This is perfectly reasonable as our MasterPages are usually in the \Masterpages folder. Instead of moving files around, which will cause other issues, I found an easy tricky to fix this. In the umbracoSettings.config file, I changed the line for the default rendering engine as follows:
<RenderingEngine>Mvc</defaultRenderingEngine>
Yes, that's right, we need to specify "Mvc". Apparently, it doesn't make any sense, but it will work, and that's what we need. By doing this, we tell Umbraco to default to MVC, but since it cannot find any views it then tries to find master pages. Probably the guys at HQ can explain this behaviour better, but for the moment it works.
Editing MasterPages in the backoffice
The second main issue was (as stated above) that Umbraco doesn’t allow the editing of MasterPages from the backoffice. It is not a major thing, but as developers, we don't really like the idea of losing the possibility of editing, or just viewing, them directly from the backoffice.
Again, Sebastiaan wrote a little plugin that will add a MasterPages editor in the Settings section. All you have to do is just unzip the files into your site folder. The link to the plugin can be found here, in the issue tracker page.
So this is how we keep using MasterPages in an updated Umbraco solution. I am not saying this is ideal, in fact, it is far from ideal, and after this, we still had a couple of minor but annoying issues that required an urgent fix. Depending on your solution you might encounter other problems that could prevent your application from working.
Next step: moving to MVC
As the solution keeps on growing, the next upgrade will certainly include the migration to MVC, as we want to make full use of the new Umbraco functionalities. This will be another interesting story to tell.
We do encourage the use of MVC over Webforms, however for some clients the cost of this development is prohibitive. Being able to extend the life of a website and still keep the Umbraco back office upgraded with the latest fixes is still offering good support to these clients.