Using Delegate Control to customize My Sites

I’m working on a model for having Site Collection metadata and was looking at how to have them available to the Index server and found out some way to add META tags with Delegate Controls.  And I also had a customer asking me about how to customize the My Sites.

For the later, Steve Peschka’s post (wow 3 years ago already!) on customizing My Sites is the best available around and there’s nothing else to add.

As discussed in his article, the trouble with customizing the My Sites is that you usually want to update the default page which is provisioned after any features are enabled.  His post describes how to have a custom master page which contains a custom control that does the required change. 

The only thing is that this control is fired up at every request.  The simple solution was to add a PropertyBag value on the SPWeb to know if work had been done or not, if not, the footprint is limited.  Nothing bad here but after working with Delegate Control, I thought of another way to do the same thing but also remove the non-required control event firing up at every request.

You can find good Delegate Control posts here:

The interesting thing about DelegateControl is that you don’t need to update master pages (except the publishing ones, which you usually do anyway), it’s only a feature that attaches a control to the page rendering.  Even more, if you’d like to update

What I essentially tried was the same code made available on Steve’s post, but instead of having the customer master page, I used a Delegate Control and copied his control’s code in mine.  My feature is scoped at the Site Collection.

The only code change I did was removing the requirement for the PropertyBag – at the end of the update, I simply used SPContext.Site.Features.Remove[MyFeatureId] to remove itself.  The control was only called once, did its changes to the default page, and remove the reference to itself.