Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3278362
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:28:22+00:00 2026-05-17T19:28:22+00:00

Using SharePoint 2010 I am trying to use the SPWebConfigModification class to make some

  • 0

Using SharePoint 2010 I am trying to use the SPWebConfigModification class to make some basic changes to web.config files on applications in the farm, including the Central Administration web.config file using web application scoped features with feature receivers handling the addition/removal of the modifications:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
        String ownerId = properties.Feature.DefinitionId.ToString();
        List<SPWebConfigModification> modsToAdd = new List<SPWebConfigModification>();

        #region Authentication Providers

        modsToAdd.Add(new SPWebConfigModification()
        {
            Name = "defaultProvider",
            Owner = ownerId,
            Path = "configuration/system.web/membership",
            Sequence = 0,
            Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute,
            Value = "FBA_AD_MP"
        });

        modsToAdd.Add(new SPWebConfigModification()
        {
            Name = "add [@name=\"FBA_AD_MP\"] [@type=\"System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"] [@connectionStringName=\"ADFBAConnectionString\"] [@enableSearchMethods=\"true\"] [@attributeMapUsername=\"userPrincipalName\"]",
            Owner = ownerId,
            Path = "configuration/system.web/membership/providers",
            Sequence = 0,
            Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
            Value = "<add name=\"FBA_AD_MP\" type=\"System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\" connectionStringName=\"ADFBAConnectionString\" enableSearchMethods=\"true\" attributeMapUsername=\"userPrincipalName\" />"
        });

        #endregion

        #region Connection Strings

        modsToAdd.Add(new SPWebConfigModification()
        {
            Name = "connectionStrings",
            Owner = ownerId,
            Path = "configuration",
            Sequence = 0,
            Type = SPWebConfigModification.SPWebConfigModificationType.EnsureSection,
            Value = "<connectionStrings />"
        });

        modsToAdd.Add(WebConfigModificationsUtility.CreateConnectionStringModification(ownerId, 1, "ADFBAConnectionString", properties.Feature.Properties["ADFBAConnectionString"].Value));

        #endregion

        WebConfigModificationsUtility.AddWebConfigModifications(webApp, modsToAdd.ToArray());
    }

The WebConfigModificationsUtility class is a simple utility shared by these feature receivers:

public static void AddWebConfigModifications(SPWebApplication webApp, params SPWebConfigModification[] modificationsToAdd)
    {
        AddWebConfigModifications(webApp, true, modificationsToAdd);
    }
public static void AddWebConfigModifications(SPWebApplication webApp, Boolean persistChanges, params SPWebConfigModification[] modificationsToAdd)
    {
        foreach (SPWebConfigModification curMod in modificationsToAdd)
        {
            SPWebService.ContentService.WebApplications[webApp.Id].WebConfigModifications.Add(curMod);                
        }

        if (persistChanges)
        {
            PersistWebConfigModifications(webApp);
        }
    }
public static void PersistWebConfigModifications(SPWebApplication webApp)
    {
        SPWebService.ContentService.WebApplications[webApp.Id].Update();                        
        SPWebService.ContentService.ApplyWebConfigModifications();
    }

Everything is working fine on content applications, but when attempting to activate features on the central admin web application, the SPWebConfigModificaiton items are never written to the web.config files. I have verified that the code is executing without exceptions. Additionally, my feature receiver attempts to remove any modifications is had made on deactivation:

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
            String ownerId = properties.Feature.DefinitionId.ToString();
            WebConfigModificationsUtility.RemoveWebConfigModifications(webApp, ownerId);
        }
public static void RemoveWebConfigModifications(SPWebApplication webApp, String ownerId, Boolean persistChanges)
        {            
            RemoveWebConfigModifications(webApp, persistChanges, webApp.WebConfigModifications.Where(x => x.Owner == ownerId).ToArray());
        }
public static void RemoveWebConfigModifications(SPWebApplication webApp, Boolean persistChanges, params SPWebConfigModification[] modificationsToRemove)
        {
            foreach (SPWebConfigModification curMod in modificationsToRemove)
            {
                SPWebService.ContentService.WebApplications[webApp.Id].WebConfigModifications.Remove(curMod);                
            }

            if (persistChanges)
            {
                PersistWebConfigModifications(webApp);
            }
        }

When this code runs on the Central Admin web application it finds the four modifications that were created in the feature activation and successfully removes them, but neither of these operations is actually changing the web.config file of the web application; it is not even touched, the time stamp for last edited date remains the same throughout.

I have found various blogs talking about the inherit trickiness of the SPWebConfigModification class, with most problems being around properly using the Name and Owner properties, as well as properly persisting changes using the SPWebService static properties, but as best I can tell I’m following all recommended practices. I’m beginning to suspect there’s a bug in the API, but I’m wondering if anyone has done this in SharePoint 2010 successfully or if I should crack open Reflector and try to see what gives?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:28:22+00:00Added an answer on May 17, 2026 at 7:28 pm

    Just like ContentService, SPWebService has an AdministrationService object which also has a WebApplications collection. Use the AdministrationService to get to your CentralAdmin web applications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to upload documents to SharePoint using web services attaching custom metadata to
I'm using the Belltown theme in a sharepoint portal and there are some styles
we are using SharePoint Server (MOSS 2007) with Windows Integrated Security. A few computers
Our team has built a site using Sharepoint and a few custom webparts. We've
I've created a list using the SharePoint (MOSS 2007) Issue Tracking List. A Comments
I'm looking at using a Windows SharePoint Services 3.0 wiki as a metadata repository.
I am progamatically creating a SharePoint site using SPWeb spWeb = spSite.AllWebs.Add(...); What code
In CAML I can query SharePoint Listitems using the Contains-element, but there is no
We're using Forms Authentication in SharePoint. When the account is created, the administrator can
I created a new SharePoint portal for testing purposes using a manually added HOSTS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.