I try to add a module into the web.config from within an event-receiver. I use SPWebConfigModification
for this. When I Update the webApp (webApp.Update()) the following error is thrown:
The specified node "configuration/system.webserver/modules" was not found in the web.config file.
But that node surely exists in the web config (and also is a quite common node). Any idea why this fails?
SPSite currentSite = GetCurrentSite(properties);
currentSite.AllowUnsafeUpdates = true;
SPWebApplication webApp = currentSite.WebApplication;
SPWebConfigModification modification = new SPWebConfigModification();
modification.Path = @"configuration/system.webServer/modules";
modification.Name = "ErrorRedirectModule";
modification.Sequence = 0;
modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
modification.Value = "<add name=\"ErrorRedirectModule2\" type=\"Tools.ErrorHttpModule, Tools, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6e907fc34eb70f91\" /> ";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
webApp.WebConfigModifications.Add(modification);
webApp.Update();
webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
});