Created
July 23, 2012 22:14
-
-
Save DavidWise/3166582 to your computer and use it in GitHub Desktop.
An httpModule that allows the master pages in SharePoint to be overridden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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