Wednesday, July 28, 2010

Using a Page Specific Master Page in SharePoint 2010

It is a common misunderstanding that you cannot have page specific masterpages in SharePoint. The standard configuration of the MasterPageFile setting in the Page directive is to use the well known ~masterurl/default.master and ~masterurl/custom.master dynamic tokens that at run-time are replaced with the site-wide 'Site Master Page' and 'System Master Page' settings. So using these tokens don't allow for having page specific masterpages in SharePoint.

There are, however, two additional tokens, the site-collection and site relative ~sitecollection/<central master page> and ~site/<local master page> static tokens from Windows SharePoint Services 3.

You can still use these static tokens in SharePoint 2010 as shown in this example:

<%@ Page language="C#" MasterPageFile="~site/_catalogs/masterpage/JBV/SiteCenterMasterPage.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>

Note how you must specify the site-collection or site relative path of the master page file location in addition to the name of the master page file.

So using the static tokens works like a breeze for web part pages in SharePoint 2010 also. I haven't tested if the Publishing feature's page layouts still are limited to the dynamic tokens. For application pages the ability to use a customized master page is new in SharePoint 2010.

1 comment:

  1. This worked for me, thanks. I was used to ASP.NET master pages, and I was almost sure this could be done in SharePoint 2010, but did not know the correct paths.

    We used it to create an IE10-compatible master page to apply to single pages for script compatibility. Hardly ideal, but it was expedient in the circumstances.

    ReplyDelete

Comments may be take some time to appear due to moderation.