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);

currentWebApp.WebConfigModifications.Add(moduleEntry);

//currentWebApp.WebService.ApplyWebConfigModifications();

SPFarm.Local.Services.GetValue<SPWebService>().ApplyWebConfigModifications();

currentWebApp.Update();

}

}

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
http://unclepaul84.blogspot.com/2010/06/sppersistedobject-xxxxxxxxxxx-could-not.html

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:
http://stefvanhooijdonk.com/2010/08/02/custom-spjobdefinition-and-access-denied-error/
http://blogs.msdn.com/b/navdeepm/archive/2010/09/15/sharepoint-2010-adding-nested-web-config-entries-using-the-spwebconfigmodification.aspx

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…

Advertisement

About bpostaci
Escalation Engineer in Microsoft.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: