I am using sp 2013. I have some custom code which is adding some webpart to the welcome page. I would like to execute this code for each new site collection depending on a template (mysites). Someone told me you can do that with a feature stapling or delegated control. Can someone tell me if it is possible with delegated control or feature stappling? And maybe how to implement this?
I think you create an event receiver scoped to Web Events and fire it when A Site is being provisioned and A site was provisioned.
It's not possible to create site collection scoped event receivers. What you need is "Feature Stapling".
You can connect a site or web scoped feature to a certain site template.
So in your case you create a site scoped feature that contains the code to manipulate the home page of the root web. If you also want to activate that kind of modifications on all newly created sub webs you should put that logic into a single web scoped feature.
So your site scoped feature not just changes the home pages but also attaches a "site created" event receiver to make sure that every sub web will get the correct homepage modifications.
After that you create a farm scoped or web application scoped feature which contains the feature stapling XML element with a GLOBAL entry. Deploy that and activate it on the farm / web application. The feature stapling will be active then and will activate your site scoped feature on every newly created site collection.