Search This Blog

Saturday, February 26, 2011

Solution to error "Security Validation for this page is invalid"

Few days back I came across this issue. It popped up whenever the page is posted back to update content to the site. On further digging into it I found this was somewhat related to the action performed within elevated code(i.e. code within SPSecurity.RunWithElevatedPrivileges).

SharePoint keep track of the requests using the token unique to the user and his request. Whenever the code is elevated the context is changed from the user to the system account.


To ensure smooth operation without the Security Validation error we should add SPUtility.ValidateFormDigest() line just before elevating the code. This MSDN article also talks about the same.