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(
delegate()
{
SPWebApplication.Lookup(SiteURI).Properties.Add(LastEmployeeIDKey, 4000);
SPWebApplication.Lookup(SiteURI).Update();
}));
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