SharePoint 2010

SharePoint:The security validation for this page is invalid. Click Back in your Web browser, Error while adding a Page to site Programmatically


You get error “The Security validation for this page is invalid” when you try to add page or move a page. This error is due to Security validation error.

This error is caused due to security validation. One way to resolve this is to turn it off in Central admin.

Navigate to

Central Administration—>application management—->web application general settings–>turn security validation off

But, if we always keep it on there might be danger of malicious code.
So, we should handle this through coding, turn off security validation for our code to execute and then again turn it on.

 

Or

 

SPWeb ospWeb = SPContext.Current.Web;
Microsoft.SharePoint.Administration.SPWebApplication webApp = ospWeb.Site.WebApplication;
webApp.FormDigestSettings.Enabled = false;
// //////
webApp.FormDigestSettings.Enabled = true;

Or

using (SPSite site = new SPSite(“http://pathik01”))
{
    site.AllowUnsafeUpdates = true;
    using (SPWeb web = site.OpenWeb())
    {
        web.AllowUnsafeUpdates = true;
        SPList list = web.Lists[“List1”];
        list.Title = “some title”;
        list.Update();
        web.Update();
    }
}

Setting the “AllowUnsafeUpdates” properties of both the SPSite and SPWeb objects to “true”, mostly will resolve this issue out if you are using a code similar to above within a webpart or an ASP.NET web application.

Leave a comment