The security validation for this page is invalid

While spending some time working with content types recently I have encountered the following error more times than I care to mention:

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

This error has plagued me throughout my content type endeavours and continued to be displayed intermittently despite having searched the web and attempted the numerous approaches suggested (i.e. SPSecurity.RunWithElevatedPrivileges(), .AllowUnsafeUpdates = true & .FormDigestSettings.Enabled = false).

Having spent time looking deeper into this it appears that there was one technique I had failed to try and wouldn’t you just know it, this one (has so far) appeared to solve all my security problems. 

If you are reading this then you are no doubt aware that for security reasons SharePoint protects the database by preventing a web application from updating unless it has passed security validation.  All of the approaches mentioned above go some way towards this but the best way to update site data is to add a page directive and FormDigest control directly to the aspx form. 

This can be done as follows:

Add page directive to top of aspx page:

<%@ Register Tagprefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>

Add FormDigest control within form tags:

<form id=”Form1″ method=”post” runat=”server”>
<SharePoint:FormDigest ID=”spFormDigestControl” runat=”server”/>


With the above in place I was able to dispense with the .RunWithElevatedPrivileges anonymous method I had wrapped around my update code (in fact I had to or it continued to throw the same error error!).

This has certainly done the trick for me, but it took a little bit of trial and error before I managed to find it. 

Useful link:

This entry was posted in SharePoint and tagged , . Bookmark the permalink.

2 Responses to The security validation for this page is invalid

  1. Ali Sher says:

    Thanks dear your search and efforts helped me to solve my problem.
    I am working to sharepoint 2010 mysites. When i click on “My Content” where personal site is created i get this error.

  2. Ryukin says:

    I googled & googled to understand why I am getting this error. Turns out that I am calling SPUtility.ValidateFormDigest() with out declaring a FormDigest control in my aspx. Thanks a lot.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s