Sharepoint 2010 Access Denied when modifing web.config with ApplyWebConfigModifications()

Ok i accept this problem is one of my favorite. After 3 hours finally i found a solution .Let me describe the error first. I have a feature receiver class which makes web.config modifications but SPWebApplication.ApplyWebConfigModifications() method cause an access denied error in activation process.Here is my code :

public override void FeatureActivated(SPFeatureReceiverProperties properties)


bool bApplyChanges = ApplyWebConfigMods(properties);

SPSite currentSite = properties.Feature.Parent as SPSite;

if (bApplyChanges)


SPWebApplication currentWebApp = currentSite.WebApplication;

string sClassName = typeof(NSF.Modules.ErrorModule).FullName;

SPWebConfigModification moduleEntry = addHttpModule(“NFSErrorModule”,

“NFSErrorModule”, PreConditions.integratedMode, sClassName, 1);







First i changed currentWebApp.WebService.ApplyWebConfigModifications()  to SPFarm.Local.Services.GetValue<SPWebService>().ApplyWebConfigModifications();

Secondly i gave permission read/write Network Service user which is my apppool identity for wss folder where web.config in it.

Third I ran powershell commadlet that change RemoteAdministratorAccessDenied propterty to false . i found it in below url

function Set-RemoteAdministratorAccessDenied-False(){ # load sharepoint api libs [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”) > $null [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint.Administration”) > $null
# get content web service $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService  # turn off remote administration security $contentService.RemoteAdministratorAccessDenied = $false  # update the web service $contentService.Update()  }

For more info:

and now its ok.

by the way default value of RemoteAdministratorAccessDenied property is totally sucking idea.And so shouldnt be someone code it with throwing explanatory exception ?

Have a nice codding…


About bpostaci
Escalation Engineer in Microsoft.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: