I have a custom web template used to provision site collections that activates features with onet.xml and is deployed as a farm solution. I've tried both feature receivers and event receivers (on WebProvisioned from the solution proposed here: Is feature activation code allowed in Web Template Project?) and neither are firing when a new site collection (or web) is provisioned using the web template or when the feature is activated.

Is there something I'm missing? Is there anyways to fire off custom code after a site collection is provisioned using a web template? Thanks.

4 Answers 4


The WebProvisioned method of the SPWebEventReceiver does not fire when a site collection is created. This is confirmed by the WebProvisioned Method MSDN page.

Depending of what your custom code does, it is best to use feature stapling either scoped to Site or Web against the site template you are using.

  • 1
    I don't think feature stapling works with webtemplates either. Nov 4, 2011 at 0:06
  • I couldn't get feature stapling to work either
    – Adam
    Nov 7, 2011 at 17:13

I experienced a similar issue. Upon creation of a new site, the features included in the <WebFeatures> node of the ONet.xml were not activated upon site creation. When navigating to '/_layouts/ManageFeatures.aspx' these features would appear to be activated but their code would not run (no files were placed from modules, breakpoints set in event receivers would not be reached). I was able to resolve the issue by making a change in my Feature nodes. Originally the nodes I used were copied from an ONET extracted from a .wsp that had been generated using the 'Save Site as Template' feature. Those nodes looked like this:

<Feature ID="{5bd39d1e-9e39-4e4f-932c-eb393b5454a4}" Name="FeatureDefinition/5bd39d1e-9e39-4e4f-932c-eb393b5454a4" SourceVersion=" /> 

When I modified the Node to resemble this:

<Feature ID="{5bd39d1e-9e39-4e4f-932c-eb393b5454a4}" /> 

The features activated as expected.


It kind of sucks but what I did in my cases is to extract the files from the webtemplate.wsp. Then edit the onet.xml file as I see fit with the features I need. Then I repackage the files/folders back into a cab/wsp.

  • I'm sorry, but I'm not sure how that relates to adding custom code? Can you please elaborate? Thanks!
    – Adam
    Nov 7, 2011 at 17:17
  • You said you are using a web template and not a site definition, correct? Your custom code would be a feature that is activated when a site is created from the web template. Since web templates don't support feature stapling like site definitions do, what I did is configure a site how I want it and save it as a web template. Then I could extract the files and edit the onet.xml to activate the features that I want activated when this template is chosen. I then repackaged them as a wsp and added it to SP. Nov 8, 2011 at 18:42

You can put your feature receiver code in a second feature. It can still be deployed as part of the same package, but would be activated separately.

The basic scenario is a feature reference in the onet.xml and then the 2nd feature is scoped for the web it is being activated on. When a new site collection is provisioned based on the web template, it will attempt to activate the web feature and perform the rest of the configuration. The great thing about this, is that since all of that configuration is maintained in a separate feature you can take advantage of the feature upgrading concepts in 2010 to maintain those sites previously provisioned.

Your Answer

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

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