Friday, August 28, 2009

The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again

Recently, I was getting this error when non-admin were trying to alter a workflow task. My code was running under elevated permission using the option first as described in my last post(using SharePoint\System) user

To fix, I need to run the code under elevated permission using second option as described in my last post(RunWithElevatedPrivileges)

    string siteURL = SPContext.Current.Site.Url;
        SPSite objSite = new SPSite(siteURL);
        SPWeb web= objSite.OpenWeb();

        web.AllowUnsafeUpdates = true;

        Hashtable taskHash = new Hashtable();
        SPListItem item = null;
        item["Status"] = "Completed";
        SPWorkflowTask.AlterTask(item, taskHash, false);
        web.AllowUnsafeUpdates = false;


sanketinfo said...

Hi Sanjay,

I must say that your article and information is very good and useful.

You save my lots of debugging time, thank you very much!!

Sanket Shah