title: ApplyWebConfigModifications not working in the Farm
body: <p>So, I am trying to deploy a Web Application feature that updates the web.config using the WebConfigModifications collection. There is lots of information on doing this including all the issues you run into so I am very confident in the code but no matter what I try the config elements are not added to the web config. This works fine in the development single server environment but does not update in the Farm.</p>
  
  <p>No errors, no log information no event messages .... nothing pointing toward why it will not update:</p>
  
  <blockquote>
  SPWebConfigModification appSettingModification = new SPWebConfigModification();<br />
  appSettingModification.Name = "add[@key=\"Key\"][@value=\"Value\"]";<br />
  appSettingModification.Path = "configuration/appSettings";<br />
  appSettingModification.Owner = "Owner";<br />
  appSettingModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;<br />
  appSettingModification.Value = __appSettingResource;<br /><br />
  if (removeModification)<br />
  {<br />
  app.WebConfigModifications.Remove(appSettingModification);<br />
  }<br />
  else<br />
  {<br />
  app.WebConfigModifications.Add(appSettingModification);<br />
  }<br />
  app.Update();<br />
  app.Farm.Services.GetValue&lt;SPWebService&gt;().ApplyWebConfigModifications();
  </blockquote>
  
  <p>==============================</p>
  
  <h1>EDIT</h1>
  
  <p>I wanted to add to this based on a suggestion by drax to reflect the ApplyWebModifications method. This method is on the SPWebService that is in the Microsoft.SharePoint.Administration namespace in the Microsoft.SharePoint assembly.</p>
  
  <p>One of the issues with using this method is that all web.config files are updated in the farm even if no modifications are actually being applied. This causes the app pools to be recycled even if you do not intend to update the web config. Reflection shows why this is happening and it is very annoying.</p>
  
  <p>Inside the method is a short foreach loop:</p>
  
  <blockquote>
  foreach (SPWebApplication application in this.WebApplications)<br />
  {<br />
  application.ApplyWebConfigModifications();<br />
  }</blockquote>
  
  <p>It is looping through each of the web applications and calling an <b>INTERNAL</b> ApplyWebConfigModifications method on the web application objects. If they just made this method public then we would be able to call the method individually without affecting the app pool recycling on web applications that are not affected by our updates. Just sayin'</p>