Saturday, July 7, 2012
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again. in webpart
ow to correct: The security validation for this page is invalid (FormDigest)
April 23, 2011 Leave a comment
How to correct the security error on a custom SharePoint web page:
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.
 
Short Answer:
Use SPUtility.ValidateFormDigest() and do not use AllowUnsafeUpdates.
 
A Less Desirable Solution (but more commonly used)
One way to get around this issue is to set the web’s (SPWeb) AllowUnsafeUpdates property to true. This is not ideal, especially when there is a more secure option.
 
A Better Solution
I needed to implement this recently and could not remember exactly what corrective code was needed, so I’m posting it here for easy recall. A co-worker (Jim Blanchard) originally tracked this solution down a good while back. This solution configures the web page to properly cache and revalidate the necessary credentials preventing the “security validation” error noted above. And, there is no need to set the AllowUnsafeUpdate spweb property to true.
 
Coding Steps:
Register the SharePoint web controls assembly in your aspx. Place this at the top of the .aspx file:
    <%@ Register TagPrefix=“SharePoint” Namespace=“Microsoft.SharePoint.WebControls” Assembly=“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c“ %>
Place the FormDigest control on the .aspx page (I place it near the end of the page):
    
Subscribe to:
Comments (Atom)
 
