Pages

October 20, 2014

Error: The Security Validation For This Page Is Invalid



Scenario:
The user is trying to edit a list item in page, via a custom web part, and the context is already under system account elevation (using SPSecurity.RunWithElevatedPrivilages() method).


Causes:
This error can occur due to one of the following reasons:

  1. Security/authentication problem: Can be fixed by delegation, and using ‘Web.AllowUnsafeUpdates’ & ‘web.Site.WebApplication.FormDigestSettings’ setting.
  2. Breaking role inheritance problem: In code, breaking the role inheritance internally flips the ‘AllowUnsafeUpdate’ flag to false, so it has to be explicitly set to true. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;970192
  3. Page timeout problem:Where user took so long to upload the attachments. See http://support.microsoft.com/kb/888828

Solution:
Actually the code already applied point 1 above. It appeared that the code internally was doing other operations right before list item save, those operations were flipping the 'AllowUnsafeUpdate' flag without an alarm.. so the solution is simply to switch it back to 'true' before the save!





No comments:

Post a Comment