I want to apply web.config modifications only on the webapplication i am installing my feature on and not all the web.configs of the farm. i am using SPWebService.ApplyWebConfigModifications , how can i do that? Help pls
views:
188answers:
3The feature you use to deploy the modifications should be web app scoped and should have a feature receiver, activating the feature on the desired web app only should do the trick.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
using (SPSite site = ((SPSite)properties.Feature.Parent))
{
SPWebApplication webApplication = site.WebApplication;
// webApplication.WebConfigModifications.Clear();
// do modifications, using the feature.GetType().FullName as the Owner
webApplication.Update();
webApplication.Farm.Services.GetValue().ApplyWebConfigModifications();
}
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
using (SPSite site = ((SPSite)properties.Feature.Parent))
{
SPWebApplication webApplication = site.WebApplication;
Collection entries = webApplication.WebConfigModifications;
for (int i = entries.Count - 1; i >= 0; i--)
{
SPWebConfigModification entry = entries[i];
if (entry.Owner == this.GetType().FullName)
entries.Remove(entry);
}
webApplication.Update();
webApplication.Farm.Services.GetValue().ApplyWebConfigModifications();
}
}
Edit
In order to manage your current modifications without going directly in the SQL Server, use this file and copy it inside the folder: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\ADMIN and access it from http://centraladministration:PORT/_admin/webconfig.aspx
Original sources TheKid blog and Harmjan Greving’s Blog
ok, the main problem is that my feature was scoped "farm", and on featureactivated a new line was added to web.config. Now everytime i install any feature, this line is always added to the web.config. I completely removed the feature, i even made a completely new feature with a new featureid (web app scoped) and still everytime i activate a feature, the same old line of the old (deleted) farm feature is added to all the web.configs.
This is crazy, how to cancel this thing, plsssss help.