SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 1 down vote accepted

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).

share|improve this answer
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 Oct 25 '11 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 Oct 25 '11 at 9:52
I had a rogue feature causing it to fail. Deleting the feature fixed the problem. – John Oct 25 '11 at 14:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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