0

I am going to modify web.config in an event receiver project SharePoint 2016. I use this piece of code in FeatureActivated function to get access to the web.config to modify it:

SPWeb myWeb = properties.Feature.Parent as SPWeb;
            SPWebApplication spWebApplication = myWeb.Site.WebApplication;
            Collection<SPWebConfigModification> webConfigCollection = spWebApplication.WebConfigModifications;
            int modCollectioncount = webConfigCollection.Count;

but this code `webConfigCollection.Count return zero. what is wrong with my way?

  • Is this piece of code executing before you do the modifications? If yes, then this is indeed right as you didn't add any custom `SPWebModification` to the `spWebApplication`'s `SPWebService` yet. Otherwise please add the code that is adding the modifications. – Darius Pintilie Nov 25 '19 at 10:49
  • This piece of code is executed before modifying the SPWebModification. But it does not return a sensible answer or something that I do not know!!! – hossein hashemian Nov 25 '19 at 16:23

0 Answers0