I am trying to add a new property to the SPFarm property bag but am getting an access denied security exception. As you can see in the code below it is begin ran with elevated privileges, so I don't really know what to try next. Any advice? Is there a better way to do what I am trying to do (store a value any instance of that webpage can grab and read/change)? I read this: http://msdn.microsoft.com/en-us/library/ee855123(v=office.12).aspx and it looks like the property bag is the best route for me, just need to figure out how to add to it...

Here is the code:

SPFarm.Local.Properties.Add(LastEmployeeIDKey, 4000);
SPSecurity.RunWithElevatedPrivileges(new SPSecurity.CodeToRunElevated(SPFarm.Local.Update));

Edit: Tried moving down to the web application level but still get the same error. Here is the code I am using now:

SPSecurity.RunWithElevatedPrivileges(new SPSecurity.CodeToRunElevated(
      SPWebApplication.Lookup(SiteURI).Properties.Add(LastEmployeeIDKey, 4000);

Thanks for any help.

Edit: Finally found a way. For those interested it is explained here: http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/05/12/how-to-write-a-value-into-the-property-bag.aspx

1 Answer 1


It is normally not a great idea to use the property bag at the farm level, I've heard of issues where problems there led to corrupt farm configuration, though I cannot remember the specific scenario. I tend to use the web application instead.

With regards to the issue, when you run with elevated privileges it will use the application pool identify. The application pool identity has full access to the web application, but not to the farm.

  • 1
    Tried at application level, still won't work. Updated code to show what I am doing now. Anymore ideas?
    – Josh
    Apr 5, 2013 at 12:59

Your Answer

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

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