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 3879366
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:43:05+00:00 2026-05-19T22:43:05+00:00

I have a little issue here regarding the modification of Web.Config files in Feature

  • 0

I have a little issue here regarding the modification of Web.Config files in Feature Stamping (SP2010 [Web Application Level Feature, Activate on default])

I’m facing two strange Issues

  1. The applied modification like (adding a child node) appears multiple times in web.config.
  2. At feature deactivating, I’m removing the modification against the owner, it gets the modification, but
    These are not removed.

I’m using the follow code snip during Feature Activation.

ModificationEntry[] enries =
{
    new ModificationEntry("someName", "someSection", SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode)
};

    SPWebApplication WebApp = (SPWebApplication)properties.Feature.Parent;
WebApp.WebConfigModifications.Clear();

foreach (ModificationEntry entry in enries)
{
   // CreateModification simply return me SPWebConfigModification
    SPWebConfigModification configModificationItem = CreateModification(entry, properties.Feature.DefinitionId.ToString());
    if (!WebApp.WebConfigModifications.Contains(configModificationItem))
    {
        WebApp.WebConfigModifications.Add(configModificationItem);
    }
}

WebApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
WebApp.Update();

This is what I’m doing at feature deactivation.

if (webApp != null)
{
    Collection<SPWebConfigModification> collection = webApp.WebConfigModifications;
    int iStartCount = collection.Count;

    // Remove any modifications that were originally created by the owner.
    for (int c = iStartCount - 1; c >= 0; c--)
    {
        SPWebConfigModification configMod = collection[c];
        if (configMod.Owner == properties.Feature.DefinitionId.ToString())
            collection.Remove(configMod);
    }

    // Apply changes only if any items were removed.
    if (iStartCount > collection.Count)
    {
        webApp.Update();
        webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
    }
}

Please Comment !

  • 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-19T22:43:05+00:00Added an answer on May 19, 2026 at 10:43 pm
    public sealed class EnableServiceAdapterFeatureReceiver : SPFeatureReceiver
        {
            private string psSiteUrl = "";
    
        #region Not Implemented
    
        /// <summary>
        /// Install of feature - not implemented
        /// </summary>
        /// <param name="properties"></param>
        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
        }
    
        /// <summary>
        /// Uninstall of feature - not implemented
        /// </summary>
        /// <param name="properties"></param>
        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
        }
    
        #endregion
    
        #region Base Class Overrides
    
        /// <summary>
        /// Activation of feature - adds modifications into web.config and change masterpage.
        /// </summary>
        /// <param name="properties"></param>
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            using (SPSite site = properties.Feature.Parent as SPSite)
            {
                psSiteUrl = site.Url;
    
                SPWebApplication webApplication = site.WebApplication;
                if (webApplication == null)
                {
                    return;
                }
    
                Modification(webApplication, site.RootWeb.Title.Trim(), true);
    
                webApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
                webApplication.Update();
            }
        }
    
        /// <summary>
        /// Deactivation of feature - removes modifications from web.config
        /// </summary>
        /// <param name="properties"></param>
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
    
            using (SPSite site = properties.Feature.Parent as SPSite)
            {
                SPWebApplication webApplication = site.WebApplication;
                if (webApplication == null)
                {
                    return;
                }
    
                Modification(webApplication, site.RootWeb.Title.Trim(), false);
    
                webApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
                webApplication.Update();
            }
        }
    
        #endregion
    
        #region Private Methods
    
        /// <summary>
        /// Modifies web.config file to add/remove SL Service Adapter support for the application 
        /// </summary>
        /// <param name="webApplication"></param>
        /// <param name="add"></param>
        private void Modification(SPWebApplication webApplication, string webTitle, bool add)
        {
            // system.serviceModel
            SPWebConfigModification svcModelConfigSection = new SPWebConfigModification();
            svcModelConfigSection.Name = "system.serviceModel";
            svcModelConfigSection.Path = "configuration";
            svcModelConfigSection.Value = "" +
                                        "<system.serviceModel>" +
                                        "<bindings>" +
                                        "<netTcpBinding>" +
                                        "<binding name=\"NetTcpBinding_IAdapterService\" closeTimeout=\"00:01:00\" openTimeout=\"00:01:00\" receiveTimeout=\"00:30:00\" sendTimeout=\"00:30:00\" transactionFlow=\"false\" transferMode=\"Buffered\" transactionProtocol=\"OleTransactions\" hostNameComparisonMode=\"StrongWildcard\" listenBacklog=\"10\" maxBufferPoolSize=\"524288\" maxBufferSize=\"65536\" maxConnections=\"10\" maxReceivedMessageSize=\"10240000\">" +
                                        "<readerQuotas maxDepth=\"32\" maxStringContentLength=\"8192\" maxArrayLength=\"16384\" maxBytesPerRead=\"4096\" maxNameTableCharCount=\"16384\" />" +
                                        "<reliableSession ordered=\"true\" inactivityTimeout=\"00:10:00\" enabled=\"false\" />" +
                                        "<security mode=\"Transport\">" +
                                        "<transport clientCredentialType=\"Windows\" protectionLevel=\"None\" />" +
                                        "</security>" +
                                        "</binding>" +
                                        "<binding name=\"tcp_Unsecured\">" +
                                        "<security mode=\"None\" />" +
                                        "</binding>" +
                                        "</netTcpBinding>" +
                                        "</bindings>" +
                                        "<client>" +
                                        "<endpoint address=\"net.tcp://slrsptm03.curie.sl.se/AdapterService/AdapterService\" binding=\"netTcpBinding\" bindingConfiguration=\"tcp_Unsecured\" contract=\"TDIWcfService.IAdapterService\" name=\"NetTcpBinding_IAdapterService\">" +
                                        "</endpoint>" +
                                        "<endpoint address=\"net.tcp://slrsptm04.curie.sl.se:8890/slHafas\" binding=\"netTcpBinding\" bindingConfiguration=\"tcp_Unsecured\" contract=\"TDIWcfService.IAdapterService\" name=\"HafasControllerService\" />" +
                                        "<!-- Endpoint adress for SL Client to MobileAdapter.ServiceController WCF service-->" +
                                        "<endpoint address=\"net.tcp://slrsptm04.curie.sl.se:8889/slMobile\" binding=\"netTcpBinding\" bindingConfiguration=\"tcp_Unsecured\" contract=\"TDIWcfService.IAdapterService\" name=\"MobileControllerService\" />" +
                                        "</client>" +
                                        "<diagnostics>" +
                                        "<!-- Enable Message Logging here. -->" +
                                        "<!-- log all messages received or sent at the transport or service model levels -->" +
                                        "<messageLogging logEntireMessage=\"true\" maxMessagesToLog=\"65000\" logMessagesAtServiceLevel=\"true\" logMalformedMessages=\"true\" logMessagesAtTransportLevel=\"true\" />" +
                                        "</diagnostics>" +
                                        "</system.serviceModel>";
            svcModelConfigSection.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
    
            // appSettings
            SPWebConfigModification appSettingsConfigSection = new SPWebConfigModification();
            appSettingsConfigSection.Name = "appSettings";
            appSettingsConfigSection.Path = "configuration";
            appSettingsConfigSection.Value = "" +
                                        "<appSettings>" +
                                        "<add key=\"MainUrl\" value=\"" + psSiteUrl + "/Planeradtrafik/default.aspx\" />" +
                                        "<add key=\"TDIUrl\" value=\"" + psSiteUrl + "/TDI/default.aspx\" />" +
                                        "<add key=\"HAFASUrl\" value=\"" + psSiteUrl + "/HAFAS/default.aspx\" />" +
                                        "<add key=\"MOBILEUrl\" value=\"" + psSiteUrl + "/MOBILE/default.aspx\" />" +
                                        "<add key=\"SessionTimeOut\" value=\"10\" />" +
                                        "<add key=\"HitPageUrl\" value=\"" + psSiteUrl + "/hitpage.html\" />" +
                                        "<add key=\"SPGroup\" value=\"" + webTitle + " Members;" + webTitle + " Visitors\" />" +
                                        "</appSettings>";
            appSettingsConfigSection.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
    
            // connectionStrings
            SPWebConfigModification connStringConfigSection = new SPWebConfigModification();
            connStringConfigSection.Name = "connectionStrings";
            connStringConfigSection.Path = "configuration";
            connStringConfigSection.Value = "" +
                                        "<connectionStrings>" +
                                        "<add name=\"SL_Portal_DBConnectionString\" connectionString=\"Data Source=.;Initial Catalog=SL_Portal_DB;Integrated Security=false;user id=sl_portal_db_user;password=[password]\" providerName=\"System.Data.SqlClient\" />" +
                                        "</connectionStrings>";
            connStringConfigSection.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
    
            // httpModules
            SPWebConfigModification httpModuleConfigSection = new SPWebConfigModification();
            httpModuleConfigSection.Name = "add[@name='Session']";
            httpModuleConfigSection.Path = "configuration/system.web/httpModules";
            httpModuleConfigSection.Value =
                "<add name=\"Session\" type=\"System.Web.SessionState.SessionStateModule\"/>";
            httpModuleConfigSection.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
    
            if (add)
            {
                webApplication.WebConfigModifications.Add(svcModelConfigSection);
                webApplication.WebConfigModifications.Add(appSettingsConfigSection);
                webApplication.WebConfigModifications.Add(connStringConfigSection);
                webApplication.WebConfigModifications.Add(httpModuleConfigSection);
            }
            else
            {
                webApplication.WebConfigModifications.Add(httpModuleConfigSection);
                webApplication.WebConfigModifications.Remove(connStringConfigSection);
                webApplication.WebConfigModifications.Remove(appSettingsConfigSection);
                webApplication.WebConfigModifications.Remove(svcModelConfigSection);
            }
        }
    
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running in a little issue here regarding jsf related dropdown selection. I have
Hey guys I have a little issue here. I have a panel where I
im having a little issue here. I have MediaElement.js set on my project. It
I have a little problem with javascript form submit issue, here is the script
I have a little issue with my hibernate logging configuration. In our application, we
Hey guys, I have a little issue here. I need my users to be
Basically I'm having a little issue here. I have a superclass and a subclass.
I have an annoying little issue here. I have code which loads content from
I'm stuck with a little issue here, say you have the following code: int
I am having a little issue here. I am a web development major and

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.