1

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' />";
    }
4
  • Is it removing the key but leaving the path, or does the key remain?
    – James Love
    Nov 17, 2010 at 9:09
  • The whole line remains. I've amended my code to following and it's still not working. public override void FeatureUninstalling(SPFeatureReceiverProperties properties) { //LoadModification(); SPWebApplication webApp = SPWebApplication.Lookup(new Uri("lgfl-cf-lt/")); //webApp.WebConfigModifications.Remove(webMod); //webApp.Update(); //webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications(); Collection<SPWebConfigModification> modifications = webApp.WebConfigModifications;
    – Kit Stead
    Nov 17, 2010 at 10:50
  • Still getting the error but having a look in the ULS and it's happening after the web.config update (which makes no sense). Apply web config modifications to web app sharepointdev WebConfigModification: Applying web config modifications to web app sharepointdev in server sharepointdev WebConfigModification: Applying web config modifications to file C:\inetpub\wwwroot\wss\VirtualDirectories\80\web.config WebConfigModification: Saved web config file C:\inetpub\wwwroot\wss\VirtualDirectories\80\web.config Updating SPPersistedObject SPWebConfigFileChanges Name=WebConfigChanges
    – Kit Stead
    Nov 17, 2010 at 13:05
  • Check this out : sharepoint.stackexchange.com/questions/30435/… Sep 12, 2012 at 13:12

2 Answers 2

1

Have you figured out yet? It sounds like it is not removing the modification because you constructed the SPWebConfigModification object yourself.

Try looping through the webApp.WebConfigModifications collection and find your modification (using owner and other attributes) and then call the remove() method.

0

I have managed to solve the issue. The name in the Name and Value properties where different.

Changing the names to match has solved this issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.