views:

446

answers:

1

When I try to update the task properties of the workflow from my webpart, I get the following exception:

Microsoft.SharePoint.SPException: Task Updates are not allowed via unstrusted code
at Microsoft.SharePoint.SPListItem.PrepareItemForUpdate(Guid newGuidOnAdd,Boolean bMigration, Boolean& bAdd, Boolean& bPublish,Object& objAttachmentNames, Object& objAttachmentContents,Int32& parentFolderId) 
at Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, BooleanbPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean
bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin,Boolean suppressAfterEvents) 
at Microsoft.SharePoint.SPListItem.Update() 
at Microsoft.SharePoint.Workflow.SPWorkflowTask.AlterTask(SPListItem task,Hashtable htData, Boolean fSynchronous)

Sample code used to update the task is:

Hashtable props = new Hashtable();
props.Add(SPBuiltInFieldId.AssignedTo, finalAssignedTo);
props.Add(SPBuiltInFieldId.Completed, "0");
props.Add(SPBuiltInFieldId.TaskStatus, "In Progress");
props.Add(SPBuiltInFieldId.Priority, "(2) Normal");
props.Add(SPBuiltInFieldId.TaskType, "0");
task.Web.AllowUnsafeUpdates = true;
bool outcome = SPWorkflowTask.AlterTask(task, props, true);

The web part is deployed under the bin directory. We have set custom CAS policy for this web part. Following is my CAS policy.

<CodeAccessSecurity>
    <PolicyItem>
      <PermissionSet class="NamedPermissionSet" version="1" Name="MyPermission" Description="Permission set for my solution">
        <IPermission class="System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Level="Medium"    />
        <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="AllFlags" />
        <IPermission class="Microsoft.SharePoint.Security.WebPartPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" version="1" Connections="true"    />
        <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"/>
        <IPermission class="System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true">
          <ConnectAccess>
            <URI uri="$OriginHost$"/>
            <URI uri="http://.*\.....\.com/.*"/&gt;
          </ConnectAccess>
        </IPermission>
      </PermissionSet>
      <Assemblies>
        <Assembly Name="MyOffice" Version="1.0.0.0" PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100df0e85cb8c660241cd3225eb653a590b91303ddbd37f8f1e661d2dffb840a258b899d6bacbbc55d03768d5ea0260ee4c8341fd447d7200abdb74b837733c3f756833e169cae803aef808530dd3ddad953a49492faee3eeba6f0dba66b0d66f1f9ca5266c69dcb799ed364db5e9e6ebcd4e81fb27365de962cbe6e7e7fba300dc"/>
      </Assemblies>
    </PolicyItem>
  </CodeAccessSecurity>

Please advise.

A: 

You need to deploy your workflow assemblies to the GAC.

this the Microsoft best practice. see the Ms patterns and pratices.

also you need to allow partially trusted callers sharepoint web part: see step 3 here:

msdn.microsoft.com/en-us/library/ms452873.aspx

Chris Jones
Hi Jones, I already followed the step 3, but its not working.