there is one very interesting class that can be used to modify web application's web.config class.
SPWebConfigModification is the class that can be used to accomplish this kind of work.
The SPWebApplication class has a SPWebConfigModifications collection property that contains all the modifications (SPWebConfigModification objects) made to this web application's web.config file. This is also where we can add new modifications and have them applied to the web.config – or remove them.
Here is a small example which demonstrate you the functionality.
Here is a sample of what the web.config..
Here is a sample example which does this task of changing the attribute to a value of "Off".
private void SimpleSample()
// Get an instance of my local web application
SPWebApplication webApp = new SPSite("http://localhost").WebApplication;
// Create my new modification to set the mode attibute to "Off".
SPWebConfigModification modification = new SPWebConfigModification("mode", "system.web/customErrors");
modification.Owner = "SimpleSampleUniqueOwnerValue";
modification.Sequence = 0;
modification.Type = PWebConfigModification.SPWebConfigModificationType.EnsureAttribute;
modification.Value = "Off";
// Add my new web.config modification.
// Save web.config changes.
// Serialize the web application state and propagate changes across the farm.
That's it. Your job is done.
This is seriously something which is very interesting. As i will find some more methods and more details, i will sure put my knowledge regarding this.