Zee99
Zee99

Reputation: 1234

ApplyWebConfigModifications to only one web application and not all the farm

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

Upvotes: 0

Views: 1722

Answers (2)

Francisco Aquino
Francisco Aquino

Reputation: 9127

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<SPWebService>().ApplyWebConfigModifications();
    }
}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
    using (SPSite site = ((SPSite)properties.Feature.Parent))
    {
        SPWebApplication webApplication = site.WebApplication;
        Collection<SPWebConfigModification> 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<SPWebService>().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

Upvotes: 0

Colin
Colin

Reputation: 10638

The 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.

Upvotes: 2

Related Questions