Tuesday, 25 March 2014

Microsoft.SharePoint.SPException: The security validation for this page is invalid. in SharePoint 2010

Microsoft.SharePoint.SPException: The security validation for this page is invalid. in SharePoint 2010
Solution:
Change the web application validation settings in Central Administration > Web Application General Settings Page.
Got to page “Web Page Security Validation” and select Security Validation is “Off” radio button.
But this will off the page validation for the complete web application and you can’t take this risk.
To resolve this we have web application’s from digest settings property which we can turf before executing the code and turn on once the site has been created using the SharePoint object Model.
Disabling the from digest :-
SPWebapplication.FormDigestSettings.Enabled = false;
Enabling the from digest :-
SPWebapplication.FormDigestSettings.Enabled = true;
SPWebapplication’s FromDigestSettings property is type of SPFormDigestSettings which related to Web page security validation. The security validation is specific to a user, site, and time period and expires after a configurable amount of time. When the user requests a page, the server returns the page with security validation inserted. When the user then submits the form, the server verifies the security validation and if it has changed, program execution is halted and a security exception is raised.