Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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' />";
    }
share|improve this question
    
Is it removing the key but leaving the path, or does the key remain? –  James Love Nov 17 '10 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 '10 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 '10 at 13:05
    
Check this out : sharepoint.stackexchange.com/questions/30435/… –  Amit Kumawat Sep 12 '12 at 13:12
add comment

2 Answers 2

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.