title: Error on updating SPPersistedObject from web part
body: <p>I have written two features in SharePoint 2007. 
  One is scoped at Site level and it basically adds a web part to the site collection where it is activated. This feature assembly is deployed under the 'bin' directory. 
  Second is Farm scoped which is my custom SPPersistedObject and is deployed in Central Administration. The assembly is added to GAC.</p>
  
  <p>From the web part I need to update my custom object. This is working fine in most cases. But on some servers that follow the least privilege administration domain accounts ' 
  <a href="http://technet.microsoft.com/en-us/library/cc263445.aspx" rel="nofollow noreferrer">http://technet.microsoft.com/en-us/library/cc263445.aspx</a>' I am getting the below error</p>
  
  <blockquote>
    <p>System.Security.SecurityException:
    Access denied. at
    Microsoft.SharePoint.Administration.SPPersistedObject.Update()
    at MyWebPart.&lt;>c__DisplayClass1.b__0()
    at
    Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object
    state) at
    Microsoft.SharePoint.SPSecurity.&lt;>c__DisplayClass4.b__2()
    at
    Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated
    secureCode) at
    Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback
    secureCode, Object param) at
    Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated
    secureCode) at
    MyWebPart.RenderWebPart(HtmlTextWriter
    writer) The Zone of the assembly that
    failed was: MyComputer</p>
  </blockquote>
  
  <p>Do I need to set any permissions or CAS policies to prevent this error?</p>
  
  <p>Below is my current CAS policy set for the web part assembly. Do I need to make any changes here.</p>
  
  <pre><code>&lt;CodeAccessSecurity&gt;
      &lt;PolicyItem&gt;
        &lt;PermissionSet class="NamedPermissionSet" version="1" Name="MyPermission" Description="Permission set for my solution"&gt;
          &lt;IPermission class="System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Level="Medium"   /&gt;
          &lt;IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /&gt;
          &lt;IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /&gt;
          &lt;IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="AllFlags" /&gt;
          &lt;IPermission class="Microsoft.SharePoint.Security.WebPartPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" version="1" Connections="true"  /&gt;
          &lt;IPermission class="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"  version="1" ObjectModel="true" UnsafeSaveOnGet="true" Impersonate="true"/&gt;
          &lt;IPermission class="System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"&gt;
            &lt;ConnectAccess&gt;
              &lt;URI uri="$OriginHost$"/&gt;
              &lt;URI uri="http://.*\.xyz\.com/.*"/&gt;
            &lt;/ConnectAccess&gt;
          &lt;/IPermission&gt;
        &lt;/PermissionSet&gt;
        &lt;Assemblies&gt;
          &lt;Assembly Name="MyWebPart" Version="1.0.0.0" PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100df0e85cb8c660241cd3225eb653a590b91303ddbd37f8f1e661d2dffb840a258b899d6bacbbc55d03768d5ea0260ee4c8341fd447d7200abdb74b837733c3f756833e169cae803aef808530dd3ddad953a49492faee3eeba6f0dba66b0d66f1f9ca5266c69dcb799ed364db5e9e6ebcd4e81fb27365de962cbe6e7e7fba300dc"/&gt;
        &lt;/Assemblies&gt;
      &lt;/PolicyItem&gt;
    &lt;/CodeAccessSecurity&gt;
  </code></pre>
  
  <p>Please advice.</p>
  
  <p>Regards,
  Jagannath  </p>