Share via


Changing the Master Page on SharePoint 2010 My Sites

Hey all, we ran across kind of a funny situation this week so I thought I would share with you what we saw and what you need to know.

We were working on customizing the master page using a feature to deploy the master and feature receiver to actually set the master page for the site to our custom master page.  Normally what you should expect is, if you're working with an SPWeb object, you want to change the CustomMasterUrl property to change the master page used for end user pages.  To change the system master page (i.e. pages that are served from the _layouts directory, the Forms folder for list and libraries, etc.) you want to change the MasterUrl property.   All of that works fine and good, in much the same way as I described back in 2007 in my posting for customizing My Sites (https://blogs.msdn.com/b/sharepoint/archive/2007/03/22/customizing-moss-2007-my-sites-within-the-enterprise.aspx).  So here's the thing that's kind of funny.

In all of the sites we tested, the rules I just described above (for CustomMasterUrl vs. MasterUrl) are correct.  However, when you are creating a personal site, i.e. My Site, i.e. a site based on SPSPERS template, it still uses the SharePoint 2007 style settings for changing the master page.  So that means you do the opposite of what I've just described.  You set the MasterUrl property of the SPWeb in order to change the master page for end user pages in personal sites.  Fortunately you can check which template your site is based on in the FeatureActivated event for an event receiver by checking the WebTemplate property of the SPWeb.

Thanks as well to Sean for helping to diagnose and track this down.

Comments

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    October 06, 2010
    Hi great article... I working to on site branding in sharepoint 2010.  I want to set custom master pages for both CustomMasterUrl pages for end users and for site master page pages like _layout pages. but only custommasterurl is showing for all the end user pages and layout pages. how to set different custom master pages for both enduser pages and layouts pages. Uri siteMasterUri = new Uri(web.Url + "/_catalogs/masterpage/Sample.master");                    Uri sysMasterUri = new Uri(web.Url + "/_catalogs/masterpage/CustomSystem.master");                    web.CustomMasterUrl = siteMasterUri.AbsolutePath;                    web.MasterUrl = sysMasterUri.AbsolutePath;                    web.Update(); Thanks in advance vardhan

  • Anonymous
    August 12, 2012
    Oh its been bothering me since last year when i left israel for US. It's a long story and a lot of mystery.

  • Anonymous
    August 12, 2012
    The comment has been removed

  • Anonymous
    September 18, 2014
    The comment has been removed