Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using a third party control for my application in SharePoint 2010 and I need to add entries in the web.config of the web application. Programmatically I have added the entries in the code and while executing the code below

webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();

I am getting Access Denied error.I have elevated the privileges before updating it. Could anypone provide a solution for this?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

My first thought was that you need to check that the app. pool account has write permissions to the web.config file. But actually I believe this API creates a timer job that will run on each server in the farm which means that your app. pool account needs rights to access the config DB.

I would try giving your app pool a/c farm admin rights temporarily to test this. You will probably need to do an iisreset. If that works you know you are on the right track and can experiment with what permissions it actually needs. Without seeing your code and log files that's the best advice I can offer.

Useful blog post (old but still good).

share|improve this answer

You're getting this error because updating the web config in this manner tries to open all web.config's on all web applications, including ones to which SPElevatedPrivileges won't have access to (because they'll be running under a different app pool identity).

Google (or Bing if you're that way inclined) around for other methods of using SPWebConfigModification.

Edit: Here's the MSDN article with some sample code: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebconfigmodification.aspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.