SPWebApplication.WebConfigModifications.Count return zero when invoking in featureActivated?

48 views Asked by At

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?

0

There are 0 answers