Supporting Multiple Master Pages in BlogEngine.NET

Supporting Multiple Master Pages in BlogEngine.NET is quite simple.  An example of a master page at dbvt.com different from my primary master page, i.e. with a different sidebar, is the Contact Page.

To get started we’re going to make a couple of changes in the BE.NET source library’s BlogBasePage.cs Class located in /web/controls/.  First we’re going to add a property to contain our master page name.

private string dbvtMasterPage = “site.master”;

public string DBVTMasterPage
{
    get { return dbvtMasterPage; }
    set { dbvtMasterPage = value; }
}

Next we’ll replace the hard-coded site.Master designation with our DBVTMasterPage property OnPreInit().

 

protected override void OnPreInit(EventArgs e)
{
    if (Request.QueryString[“theme”] != null)
             _Theme = Request.QueryString[“theme”];

   MasterPageFile = Utils.RelativeWebRoot + “themes/” +
             _Theme + “/” + this.DBVTMasterPage;

Now in the CodeBehind.cs of our Contact Page we’ll add an OnPreInit() method and specify our DBVTMasterPage property.

 

protected override void OnPreInit(EventArgs e)
{
    this.DBVTMasterPage = “contact.master”;
    base.OnPreInit(e);
}

The only thing left to do is create the contact.master page!

Article written by

A long time developer, I was an early adopter of Linux in the mid-90's for a few years until I entered corporate environments and worked with Microsoft technologies like ASP, then .NET. In 2008 I released Sueetie, an Online Community Platform built in .NET. In late 2012 I returned to my Linux roots and locked in on Java development. Much of my work is available on GitHub.