views:

118

answers:

1

I'm having a strange security problem with a SharePoint workflow. Particular calls seem to result in the following exception:

Microsoft.SharePoint.SPException: The security validation for this page is invalid.

I've come across this error before and the simple fix is

web.AllowUnsafeUpdates = true;
...
web.AllowUnsafeUpdates = false;

However I've never once encountered this problem inside a workflow before since a workflow runs as system. I first got this error in a code activity where I set the value of a column on the list item. Wrapping the item.Update in AllowUnsafeUpdates fixed it.

After the code activity I have a CreateTask activity. This also causes the same error but only after running the code inside the activity's MethodInvoking.

In both cases there's a SPListItem.UpdateItem involved within the stack trace. This call is failing a security check. I don't know anything about how this check works so I don't know where to look next.

This is a strange one, because this SharePoint dev machine has been working fine for some time. No other projects or workflows exhibit this behaviour so that rules out an installation problem. There's just something about this particular workflow.

[UPDATE] I've gotten around the issue by just creating a new project and building it up again. I still have the broken one and I'd still like to figure out the problem with it. I'd appreciate any suggestions of what it might be.

+1  A: 

I haven't seen this happen in a workflow, but there are two cases where I have seen it. Maybe one of those will be helpful.

  1. Updating an item on the GET of a SharePoint page instead of on the POST (ie, Page.IsPostBack is false). Setting AllowUnsafeUpdates to true fixes it.
  2. Updating an item on the POST of a SharePoint page when impersonating or running with elevated privileges. Calling SPUtility.ValidateFormDigest fixes it.
Rich Bennema