Wednesday, September 14, 2011

ApplyWebConfigModifications fails inspite of modifying web.config

Today I ran into issue of ApplyWebConfigModifications not fetching recent changes from web.config. Knew this could be due to config database in picture. And there it was got saved by clearing the DB entries with help of follwoing code for console application

string webAppUrl = @("");
SPSite site = new SPSite(webAppUrl);
SPWebApplication webApp = site.WebApplication;
webApp.WebConfigModifications.Clear();
webApp.Update();
SPWebService service = SPWebService.ContentService;
service.WebConfigModifications.Clear();
service.Update();
service.ApplyWebConfigModifications();



Cheers
Amitabh Wankhede!!