I am trying to get subsites of my parent site to inherit the same masterpage as their parent. I have a feature stapled to all the default site templates that contain my master page.

I have created a Event Receiver called ChildSiteInit. It has the following code:

using Microsoft.SharePoint;

namespace SP_Intranet.ChildSiteInit
    public class ChildSiteInit : SPWebEventReceiver
        public override void WebProvisioned(SPWebEventProperties properties)
            SPWeb childSite = properties.Web;
            SPWeb topSite = childSite.Site.RootWeb;
            childSite.MasterUrl = topSite.MasterUrl;
            childSite.CustomMasterUrl = topSite.CustomMasterUrl;
            childSite.AlternateCssUrl = topSite.AlternateCssUrl;
            childSite.SiteLogoUrl = topSite.SiteLogoUrl;

This is taken from Inside Microsoft SharePoint 2010 (direct copy bar the namespace).

It is displayed in my feature and the feature is deployed. The feature is deployed at site collection level.

When I create a new sub site the parent masterpage is not inherited.

Updated code removing usings

1 Answer 1


Is this in a sandboxed solution?

Is this in a Publishing Site?

Also, remove the unneeded usings (right click the code, Organise Usings) - Security, Utilities, Workflow. Keeps the code cleaner a bit.

The code itself looks fine, try putting a breakpoint on the first line and debug, see if it bails out at any point and gives you clues as to why (I currently have a problem trying to set the Navigation settings of a Publishing site using the exact same event receiver, and it's bailing out, as I think the sandboxed environment can't handle it. I had to debug to reveal this).

  • Not sandboxed. I get this on all site types. Thanks for the tips about using I will remove them. I will try some debugging and see what I can come up with.
    – John
    Commented Oct 25, 2011 at 8:00
  • The code is not being hit by the debugger. Not sure why but that would be why it is not being applied.
    – John
    Commented Oct 25, 2011 at 9:52
  • I had a rogue feature causing it to fail. Deleting the feature fixed the problem.
    – John
    Commented Oct 25, 2011 at 14:26

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.