Best Practice Feature Stapling
Whoever have tried using feature stapling for customizing the out of the box
functionality of a site upon creation (e.g. My Site customization) would note
that there is no easy way to customize the existing functionality
through feature receiver on Staplee.
For e.g. you can easily add new components such as lists and libraries, activate additional features through feature receiver but it is usually a nightmare to modify existing functionality such as changing settings of out of the box lists being created as part of site provisioning or automatically applying a custom master page on newly created site.
This problem stems from the fact that the features are activated on a newly created site even before the site itself has actually finished provisioning. Since, your feature staplee would be just like other features being activated on a newly created site, the feature receiver code would execute even before the site has been fully created. So, let's suppose if you try to modify the versioning settings on a "Personal Documents" library on a newly created my site from a feature staplee feature receiver, it is likely that the out of the box library would not be found by your code as it is still being provisioned.
So, the best practice to actually do such a thing would be to use the delegate control with your feature staplee to execute your code instead of using a feature receiver. All OOB Mater Pages have a delegate control called "AdditionalPageHead" which can be overriden to execute your own code whenever a site is loaded in the browser. This ensures, that the site has finished provisioning by the time your code is executing.
Following are few blogs that discuss this approach:
http://habaneroconsulting.com/blog/posts/SharePoint_2007_Feature_Stapling_and_Feature_Receiver.aspx
http://blogs.salmanghani.info/?tag=feature-stapling
For e.g. you can easily add new components such as lists and libraries, activate additional features through feature receiver but it is usually a nightmare to modify existing functionality such as changing settings of out of the box lists being created as part of site provisioning or automatically applying a custom master page on newly created site.
This problem stems from the fact that the features are activated on a newly created site even before the site itself has actually finished provisioning. Since, your feature staplee would be just like other features being activated on a newly created site, the feature receiver code would execute even before the site has been fully created. So, let's suppose if you try to modify the versioning settings on a "Personal Documents" library on a newly created my site from a feature staplee feature receiver, it is likely that the out of the box library would not be found by your code as it is still being provisioned.
So, the best practice to actually do such a thing would be to use the delegate control with your feature staplee to execute your code instead of using a feature receiver. All OOB Mater Pages have a delegate control called "AdditionalPageHead" which can be overriden to execute your own code whenever a site is loaded in the browser. This ensures, that the site has finished provisioning by the time your code is executing.
Following are few blogs that discuss this approach:
http://habaneroconsulting.com/blog/posts/SharePoint_2007_Feature_Stapling_and_Feature_Receiver.aspx
http://blogs.salmanghani.info/?tag=feature-stapling
Comments