Answered by:

Using SPWebConfigModification code seems to clear all manual entries in the web.config file

Question

I'm using SPWebConfigModification() ++ to add WCF service bindings and client configurations. The code where tested ok in development and test environment, but it failed hard in the production farm. I activate the web.config changes in a feature scoped to the Web Application level. When I activated the feature (in production) it added my changes as it should, BUT it also cleared several of the manual changes that had been made to the web.config file (such as som Ajax settings). I did not clear all of my manual changes - just some.

Bug? Anybody any idea on what was going on in my environment?

Best regards,Frode

Monday, March 02, 2009 6:46 AM

Answers

To remove web.config entries you should make sure you check SPWebConfigModification owner before you remove them. Don't remove them thisApplication.WebConfigModifications.Clear();

Also if you have a feature to add these entries then don't combine adding and removing entries together, remove entries on feature deactivate and add entries on feature activation. This to avoid calling ApplyWebConfigModifications() twice. This is very important in case of FARM deployment.

While working on SPWebConfigModification object one thing I found out that both "name" and "path" properties need to be carefully used as these two properties tells SPWebConfigModification object what need to be added/removed and where it can be added/removed.

It doen't work for me because I am adding a key in "configuration/system.web/compilation/assemblies" that is actually not supported by SPWebConfigModifications (I should use something like custom CAS instead... :)). Try it and tell me if it worked for you!Blog de Barto MolinaMicrosoft MCP 6608632

To remove web.config entries you should make sure you check SPWebConfigModification owner before you remove them. Don't remove them thisApplication.WebConfigModifications.Clear();

Also if you have a feature to add these entries then don't combine adding and removing entries together, remove entries on feature deactivate and add entries on feature activation. This to avoid calling ApplyWebConfigModifications() twice. This is very important in case of FARM deployment.