The product of many evenings in hotels recently, I’m proud to present, my Application Master Page Changer.
Application master pages are tricky – out of the box in SharePoint 2007, there is no way of changing the master page used for ‘administrative’ pages. Unfortunately, those administrative pages include things like the recycle bin, file upload, and the ‘View all site content’ pages – things that users will likely see.
Well, folks have found a solution to this – using an HTTP Module to intercept pages using the normal application.master and redirecting it to use your custom one. This works pretty well, but I was always a bit uncomfortable – what if you only want this to happen for particular site collections, or specific sites within a Web Application? What if you want to use many alternate master pages? Most examples are hard coded to one, and on throughout the web app. There is also the question of pushing the module out to all front-end web servers and putting the config entries you need into web.config – this never gets mentioned.
I’d tried knocking up an HTTP Module to forward to certain master pages for certain URL patterns, but it was awkward to configure, complex, and adding new sites/site collections could be a bit annoying – basically, a nightmare to configure. Installation was fairly manual, too.
What we really need, I thought, is some way of just turning on/off the master pages being used with Features. And that’s what I’ve built!

This is not a full solution – it couldn’t be, I don’t know what master pages you want to use! Rather, it’s an example, and most developers would be able to build a solution based on this in very short order. It will allow you to replace the application.master and simple.master pages either for all sites in a site collection, or for just a specific site. There are other master pages but I chose to ignore them – you could add support for them easily enough based on what I’ve built.
The project in this zip file is a Visual Studio 2008 project built with the fantastic WSP Builder Extensions – I strongly recommend using them in your SharePoint development. Anyway, the solution contains 5 main elements:
- Web Config Feature – This Web Application-level feature adds the HTTP Module to the Web.Config file for the web application it is active in.
- SP Site Changer Feature – This Site Collection-level feature sets the path to the simple.master and application.master files for the site collection it is active in. Paths to the new master pages are set in the Feature.xml.
- SP Web Changer Feature – The Site-level feature set the path to the simple.master and application.master files for the site it is active in. This overrides the SP Site Changer Feature if it is active. Paths to the new master pages are set in the Feature.xml.
- Burns. Andrew. Master Page Changer .Changer HTTP Module – The master page changer HTTP Module itself!
- The Master Pages to go in the LAYOUTS folder
How does it work?
Well, when you install the WSP, the Burns.Andrew.Master Page Changer.dll assembly will be put in the GAC. Activating the Web Config Feature will change the Web.config file to add that HTTP Module to the processing pipeline. Every page request will be checked to see if it uses simple.master or application.master. If it does, the Changer HTTP Module will open the site collection and site at that URL, and check their properties. If they’ve got the properties set by the SP Site Changer Feature or SP Web Changer Feature, then the Changer HTTP Module redirects the request to use the appropriate master pages.
This approach has several advantages:
- Customisation can be turned on or off at a Site Collection or Site level. You could even change this to work for an entire Web Application too, but that didn’t seem worth the effort.
- Several brands can be supported by the same HTTP Module – it reads the master page it should use from the properties on the Site/Site Collection. You could create multiple versions of the SP Web Changer Feature and SP Site Changer Feature features setting different master pages to be used.
- Minimal changes to the web.config file – and all changes are automatically rolled out across your servers.
So, hopefully this will allow your developers to turn out custom master pages for Application Pages and plug them together into a solution reasonably quickly.
Installation
- Install as normal for a WSP.
- In Central Admin go to Application Management > Manage Web Application Features.
- Activate the feature Burns.Andrew.Master Page Changer Web Config Feature for the web application.
- Go to the Site Collections/Sites within that web application at turn on features as required.