I’m trying to do dynamic switching of the master page in SharePoint 2007 publishing site.
I’m following this example which uses a HTTP Module
http://ranaictiu-technicalblog.blogspot.com/2009/10/sharepoint-dynamically-change-master.html
Here is my code
public class SwitchMasterPage : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null)
{
page.PreInit += new EventHandler(page_PreInit);
}
}
void page_PreInit(object sender, EventArgs e)
{
Logger.Verbose("SwitchMasterPage:page_PreInit", "I'm in the preInit event.");
}
}
Everything is working fine when the current page type is an Application Page, however when the page type is a Publishing page (e.g. BlueBand.master) the page_PreInit procedure is never called - it is still being registered with the event handler though.