I have a custom master page applied to my site collection. When i create a new sub site, it doesn't come with this custom master page applied to it. I can always go to /_layouts/changesitemasterpage.aspx on my root site and check the options "Reset all subsites to inherit this Site Master Page setting" and it will apply the same master to every single subsite.

I'm trying to make a feature that automatically does that when i create a new subsite. Is that possible to be done?

2 Answers 2


1) Create a feature, with event receiver

public class CustomFeatureReceiver : Microsoft.SharePoint.SPFeatureReceiver {
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
        using(SPSite site = new SPSite("")) {
            using(SPWeb web = site.OpenWeb("")) {
                string url += "_catalogs/masterpage/custom.main.master";
                web.CustomMasterUrl = url;
                web.MasterUrl = url;

2) Create another feature and staple your first feature to the site definition


3) Or create a custom site definition with your feature

  • How do you set it in a custom site definition? Would it be in the Onet.xml - under <Configuration> element. I see there is a MasterUrl attribute, but removing that attrib doesn't inherit the parent's masterpage.
    – Dan Tshin
    May 17, 2012 at 23:34

If you open the master page gallery in SharePoint Designer you should able to set the default master page in your site, which I think should set all newly created subsites to use that master page.

  • James are you sure you can set the default master page in SP Designer.If yes can you please elaborate? Thanks
    – naijacoder
    Dec 1, 2011 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.