I am trying to remove the user solution. I used


But I am getting error

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

I tried below things to resolve issues :

  1. Used web.allowunsafeupdate but nothing happened.
  2. Used webApp.FormDigestSettings.Enabled = true. It worked on one environment but gave access denied error on another environment. To check for access denied I tried to use user token of system account to impersonate the permission level and then created webapp object using that token, but still it gave access denied error.
  3. complete code is inside Runwithelevatedprivilege.

Can anyone suggest any solution.

1 Answer 1


Try calling SPUtility.ValidateFormDigest() before going into RunWithElevatedPrivileges, like so:

    // do some elevated stuff

The problem is that when you try to do something with the object model that requires form digest validation (i.e. many write operations), behind the scenes SharePoint tries to do the validation right then and there. But the form digest is both site specific and user specific, and once you're in the elevated block, the user is no longer the same as the user that the form digest was generated for. By explicitly validating the form digest before RunWithElevatedPriviliges, it will validate in the correct user context and subsequent write operations will see that it has already been validated and skip it.

Also, if you're code is running on a page or web service, then it should be running in a non-GET request (i.e. POST, PUT, etc.).

If you satisfy both of these conditions, you will not need to allow unsafe updates.


SPUtility.ValidateFormDigest method

  • Thanks. SPUtility.ValidateFormDigest() worked.
    – notorious
    Commented Feb 11, 2019 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.