I'm working on a project in SP/VS2010 that contains features with event receivers that require access to appsettings keys in the web application's web.config.

While I've checked that the features can acces these keys when (e.g.) activated from the web UI, they do not have access when activated via VS's Build > Deploy Solution menu item or via powershell.

I've established that this is because when the featre is activated by VS or Powershell, the call to ConfigurationManager.AppSettings in the feature receiver does not correspond to the web application's web.config. Instead, it corresponds to vssphost.exe's .config or powershell.exe's .config respectively.

While I can probably throw together a Powershell script to copy the required keys to powershell.exe.config before I try to use these features via PS, I can't think of a neat way to do copy the keys to vssphost4.exe.config every time I use Build > Deploy Solution in VS2010.

I can't be the only person with this issue, but I've been unable to find anything via Google. Is there a standard way to do this?

3 Answers 3


I would recommend NOT to store appsettings in the web.config - use any other methods. SPWebConfigModifications are not reliable in all scenarions (just Bingle it and you'll find a plethora of posts about it).

For instance the hierarchichal configuration storage in the P&P SharePoint guidance is a great way to store settings (http://spg.codeplex.com)

  • +1 for not using appsettings. Alternative to configuration manager is to simply use properties on SPFarm or SPWeb (rootweb) Aug 3, 2011 at 16:23
  • I agree with @wictor that you should minimize the altering of the web.config file. You could however either use the P&P way or write your own "settings provider" that reads from a app.config file in let's say a feature directory. I've made some test with an approach like this (johanleino.wordpress.com/2011/01/06/…) Aug 8, 2011 at 10:42
  • I've used SPWebConfigModifications for several solutions now and have yet to encounter a problem with it. Custom, list based settings providers are the way to go for basic settings, but there are times where you will need to update the web.config (i.e. adding custom HttpHandlers or HttpModules, adding custom configuration for other libraries, etc.). Aug 22, 2011 at 17:42
  • I also agree with @victor. We use the property bag to store settings. But what if you use third party components that use the config file? In our case we use the enterprise library for logging. In the web.config we have a entry pointing to a specific enterprise library config file. But this one entry in the web.config is necessary - as far is I know.
    – tschuege
    Jan 9, 2013 at 9:52

If you're modifying the web.config in a feature, the recommended practice is using SPWebConfigModification. This way, changes are kept in sync across all your web front ends.

Read this MSDN article on using the SPWebConfigModification: http://msdn.microsoft.com/en-us/library/bb861909.aspx

  • This is very helpful, as I hadn't really worried yet about how I was going to automate getting the changes into the application's web.config, but I'm specifically asking how to automate getting them into vssphost4's config for VS to use in deploying.
    – Rawling
    Aug 3, 2011 at 8:30
  • Note that SPWebConfigModification has a number of caveats and will not always be promoted/demoted from all web.config on all WFE's Aug 3, 2011 at 13:26

If you do want to use web.config you must point to the web.config file yourself, when running from powershell/stsadm because in that case you do not have a web context. You might be able to do this by accessing the SPWebApplication from the feature parent and determine its physical folder on the server. Than you could load the web.config using Linq To Xml and query for the wanted appSetting.

Another approach could be not use a feature at all but rather a command line tool.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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