I'm using the code below to add and remove a web.config change when my solution is being installed and uninstalled. The addition is working perfectly, however, the removal (although updating the web.config) isn't removing the line.
Can some please proof this code.
SPWebConfigModification webMod = null;
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
LoadModification();
SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://sharepointdev/"));
webApp.WebConfigModifications.Add(webMod);
webApp.Update();
webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
LoadModification();
SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://sharepointdev/"));
webApp.WebConfigModifications.Remove(webMod);
webApp.Update();
webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
}
void LoadModification()
{
webMod = new SPWebConfigModification();
webMod.Path = "configuration/system.webServer/modules";
webMod.Name = "add [@name='PageNotFoundModule'][@preCondition='integratedMode'][@type='PageNotFoundManager.PageNotFoundModule, PageNotFoundManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c0aac803e4855c6f']";
webMod.Sequence = 0;
webMod.Owner = "PageNotFoundManager";
webMod.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
webMod.Value = "<add name='PageNotFoundManager' preCondition='integratedMode' type='PageNotFoundManager.PageNotFoundModule, PageNotFoundManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c0aac803e4855c6f' />";
}