ApplyWebConfigModifications not working on farm

So I am trying to deploy a web application feature that updates the web.config with the WebConfigModifications collection. There is a lot of information on this, including all the problems you are running into, so I am very confident in the code, but no matter what I try, the config items are not added to the web config. This works fine in a single server development environment, but is not updated on the farm.

No errors, no log information, no event messages ... nothing indicates why it won't be updated:

SPWebConfigModification appSettingModification = new SPWebConfigModification ();
appSettingModification.Name = "Add [@key = \" Key \ "] [@value = \" Value \ "]";
appSettingModification.Path = "configuration / appSettings";
appSettingModification.Owner = "Owner";
appSettingModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
appSettingModification.Value = __appSettingResource;

if (removeModification)
{
app.WebConfigModifications.Remove (appSettingModification);
}
else
{
app.WebConfigModifications.Add (appSettingModification);
}
app.Update ();
app.Farm.Services.GetValue <SPWebService> () ApplyWebConfigModifications ().

===============================

EDIT

I wanted to add to this based on drax's suggestion to reflect the ApplyWebModifications method. This method is located in SPWebService, which is located in the Microsoft.SharePoint.Administration namespace in the Microsoft.SharePoint assembly.

One problem with this method is that all web.config files are updated in the farm, even if no modifications are applied. This leads to reuse of application pools, even if you are not going to update the web configuration. Reflection shows why this is happening and it is very annoying.

Inside the method, a short foreach loop is used:

foreach (SPWebApplication application in this.WebApplications)
{
application.ApplyWebConfigModifications ();
}

It loops through each of the web applications and calls the INTERNAL ApplyWebConfigModifications method on the web application objects. If they just made this method public, we could call the method individually without affecting the application pool utility in web applications that are not affected by our updates. Just say

+1


source to share


2 answers


the problem is possible in your call to ApplyWebCOnfigModifications () instead of:

app.Farm.Services.GetValue () ApplyWebConfigModifications ().

using:



app.Farm.Servers.GetValue <SPWebService

> () ApplyWebConfigModifications () ;.

The second code actually calls the service responsible for updating the web.config files.

Sidenote: This code will actually open all webconfig files in all web applications installed on the server / farm :), but it will only update the needed ones. If you use a reflector to scan this method, you will see a good example of using a foreach loop :)

0


source


This problem is a bug. I think.



SPWebService.ApplyWebConfigModifications()

public void ApplyWebConfigModifications()
{
  if (base.Farm.TimerService.Instances.Count > 1)
  {
    SPWebConfigJobDefinition definition = new SPWebConfigJobDefinition(this);
    definition.Schedule = new SPOneTimeSchedule(DateTime.Now);
    try
    {
      definition.Update();
      return;
    }
    catch (Exception exception)
    {
      if (exception is SPDuplicateObjectException)
      {
        throw new InvalidOperationException(SPResource.GetString("WebconfigModificationAlreadyRunning", new object[0]), exception);
      }
      throw;
    }
  }
  string strMessage = string.Empty;
  **foreach (SPWebApplication application in this.WebApplications)**
  {
    ULS.SendTraceTag(0x38386866, ULSCat.msoulscat_WSS_Topology, ULSTraceLevel.Medium, "Apply web config modifications to web app {0} ", new object[] { application.GetResponseUri(SPUrlZone.Default).ToString() });
    try
    {
      application.ApplyWebConfigModifications();

      

0


source







All Articles