You can use this code in the feature actived.
try
{
SPWebApplication app = null;
SPWeb web = null;
SPSiteCollection site = properties.Feature.Parent as SPSiteCollection;
if (site == null)
{
web = properties.Feature.Parent as SPWeb;
if (web != null)
app = web.Site.WebApplication;
}
else
app = site.WebApplication;
SPWebConfigModification modification = new SPWebConfigModification();
modification.Name = "add [@Assembly='System.
modification.Path = "configuration/system.web/
modification.Value = @"
modification.Owner = Assembly.GetExecutingAssembly(
modification.Sequence = 0;
modification.Type = SPWebConfigModification.SPWebC
app.WebConfigModifications.
SPFarm.Local.Services.
}
catch (Exception ex)
{
}
The example code could be changed easily to remove the configuration change, as in the following example:
app.WebConfigModifications.Remove(modification);