views:

954

answers:

2

We have a SharePoint farm with multiple WFEs. A new application requires us to write some custom code to the web.config during deployment. What is the best way modify the the web.config file during deployment, ensuring that each WFE in the farm get updated?

+5  A: 

I'm assuming you'll be deploying your code via a WSP; if not, using a tool like WSPBuilder is a great starting place that allows you to get rolling without forcing you to learn all of the intricate details of solution package construction.

You should leverage the SPWebConfigModification type from within a custom SPFeatureReceiver. Normally, the FeatureActivated method of the SPFeatureReceiver would be coded to write the changes out to the web.config files impacted by your activation. Those same changes would then be retracted in the FeatureDeactivating method.

The nice thing about the SPWebConfigModification type is that SharePoint takes care of determining which web.config files should be modified -- across servers and across extended web apps.

I hope this helps!

Sean McDonough
+3  A: 

As part of your deployment, use the SPWebConfigModification class to add/remove entries from web.config. SharePoint will manage updating the WFEs for you if you use this.

This article is a great summation of the gotchas involved and contains links to other helpful resources.

Alex Angas
Good link, Alex; lots of useful tips in that one!
Sean McDonough
Great link, here's some more (class to add/remove appsetings)http://sharepointlive.blogspot.com/2009/02/how-to-add-or-remove-appsettings.html
Colin