SharePoint use a different Master Page for a single page

Posted: May 24th, 2014 | Author: | Filed under: SharePoint, Tech | No Comments »

After creating a custom error page in SharePoint I had a specific requirement for this page to use a custom design for which a Master Page was already created.

After taking a look at PublishingLayoutPage class in Microsoft.SharePoint.Publishing I saw that is looks for a querystring “OverrideMasterPageUrl” , by appending this querystring to a publishing page and specifying a valid location to a MasterPage file it will do what the name suggest and override the default Master file for the site.

contoso.com/pages/error.aspx?OverrideMasterPageUrl=/_catalogs/MasterPage/mycustom.master

Continuing to look at the PublishingLayoutPage  class you can also set the string property  ”MasterPageFile” to the URL of your custom Master Page file so if you are using code behind with your page layout this is also an option instead of using the querystring method,  in your code file you can do this


namespace MyNameSpace
{
   public class ErrorLayoutPage : Microsoft.SharePoint.Publishing.PublishingLayoutPage
   {
    protected override void OnPreInit(EventArgs e)
    {
     this.MasterPageFile = "/_catalogs/MasterPage/mycustom.master";
    }
   }
}

 

Be Sociable, Share!

No related posts.



Leave a Reply