Everything SharePoint and XAML

My continuous learning of SharePoint, XAML, Silverlight, Windows Phone 7, Windows 8, Office, VSTO, C#…

Customize application.master

Posted by Steve Pietrek on January 29, 2008

I have been doing some research on customizing application.master. I found a good KB on Microsoft’s web site listing two ways to customize application.master.

  1. Customize the files in the Layouts folder (recommended)
  2. Create a custom Layouts folder

The two methods above work well.

I have been messing around with an application development method using a feature, HttpModule, and SPWebConfigModification. The premise of the feature is for every page, in the PreInit event, I check to see if the page’s current MasterPageFile is application.master. If it is, I set the MasterPageFile to my custom application.master. I plan on blogging on this method soon.

Advertisements

One Response to “Customize application.master”

  1. I have code samples for you!

    namespace CustomDesign
    {
    public class CustomPageInit : IHttpModule
    {
    public void Init(HttpApplication context)
    {
    context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
    }

    void context_PreRequestHandlerExecute(object sender, EventArgs e)
    {
    HttpApplication httpApp = sender as HttpApplication;

    if (httpApp != null)
    {
    Page page = httpApp.Context.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.MasterPageFile != null)
    {
    if (page.MasterPageFile.ToLower().Contains("application.master")) {

    SPWeb objWeb = SPContext.Current.Web;

    if (objWeb.MasterUrl.Contains("default.custom.master"))
    {
    objWeb.AllowUnsafeUpdates = true;
    objWeb.Update();
    string strTmp = page.MasterPageFile.ToLower().Replace("application.master", "application.custom.master");
    page.MasterPageFile = strTmp;
    }
    }
    }
    }

    public void Dispose()
    {
    }
    }
    }

    In the web.config, append that line into the httpmodule section

Sorry, the comment form is closed at this time.

 
%d bloggers like this: