Some things in SharePoint are pretty hard to gain insight on, especially while doing support, and in my opinion the WebConfigModifications is really one of them.
Why? Well.. if something is not right in there it could crash your WebApplication and there is not much you (as an admin) can do about it right?
Even we as developers have a hard time of getting this right. So that’s why I’ve developed YAAP (Yet Another Application Page) that displays per WebApplication what all the WebConfigModifications are and the best thing is.. you can delete a modification as well (bet you didn’t see that one coming ;) !
public class Settings : ApplicationsManagementPage
{
protected SPGridView gridView;
protected WebApplicationSelector webApplicationSelector;
protected override void CreateChildControls()
{
if (webApplicationSelector != null)
{
SPWebApplication webApplication = webApplicationSelector.CurrentItem;
gridView.DataSource = GetAllWebConfigModifications();
gridView.DataBind();
}
base.CreateChildControls();
}
public void DeleteLink(object sender, EventArgs e)
{
foreach (string modificationid in RetrieveIDs())
{
if (!string.IsNullOrEmpty(modificationid))
{
DeleteModification(int.Parse(modificationid));
}
}
}
private string[] RetrieveIDs()
{
string[] modificationIds = null;
if (((base.Request != null) && (base.Request["ctl00$PlaceHolderMain$HiddenSiteSelections"] != null))
&& !string.IsNullOrEmpty(base.Request["ctl00$PlaceHolderMain$HiddenSiteSelections"]))
{
modificationIds =
base.Request["ctl00$PlaceHolderMain$HiddenSiteSelections"].ToString().Split(new Char[] { '#' });
}
return modificationIds;
}
private DataTable GetAllWebConfigModifications()
{
//I make use of a DataTable to add an indexer to each SPWebConfigModification object,
//by making use of an indexer I make sure that whenever there are multiple entries that
//are the same I remove the right one
DataTable dataTable = new DataTable();
dataTable.Columns.Add("Id");
dataTable.Columns.Add("Name");
dataTable.Columns.Add("Path");
dataTable.Columns.Add("Owner");
dataTable.Columns.Add("Sequence");
dataTable.Columns.Add("Type");
dataTable.Columns.Add("Value");
int webConfigModificationId = 1;
foreach (SPWebConfigModification modification in webApplicationSelector.CurrentItem.WebConfigModifications)
{
DataRow row = dataTable.NewRow();
row["Id"] = webConfigModificationId.ToString();
row["Name"] = modification.Name;
row["Path"] = modification.Path;
row["Owner"] = modification.Owner;
row["Sequence"] = modification.Sequence;
row["Type"] = modification.Type;
row["Value"] = modification.Value;
dataTable.Rows.Add(row);
webConfigModificationId++;
}
return dataTable;
}
private void DeleteModification(int modificationId)
{
DataTable modifications = GetAllWebConfigModifications();
SPWebApplication webApplication = webApplicationSelector.CurrentItem;
webApplication.WebConfigModifications.RemoveAt(modificationId);
webApplication.Update();
webApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
}
Will put the solution up on CodePlex this week so you can download it and see for yourself what all the modifications are in for your WebApplications!