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.