Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An httpModule that allows the master pages in SharePoint to be overridden
using System;
using System.Web;
using System.Web.UI;
using System.IO;
public class MasterPageModule : IHttpModule
{
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)
{
Page page = sender as Page;
if (page != null)
{
// Is there a master page defined?
if (page.MasterPageFile != null)
{
// only change the application.master files as those are the offenders
if (page.MasterPageFile.Contains(“application.master”))
{
page.MasterPageFile =/_catalogs/masterpage/MyCustom.master”;
}
}
}
}
public void Dispose()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment