Sunday, June 27, 2010

The Security Validation for this page is invalid

If we update the Content type in SharePoint ie) customContentType.Update(true); For child updation... It will show the above problem for that I have a solution. that is

SPSecurity.RunWithElevatedPrivileges(delegate()
{


using (SPSite spSite = new SPSite(strUrl, SPContext.Current.Site.SystemAccount.UserToken))
{
spSite.AllowUnsafeUpdates = true;
using (SPWeb spWeb = spSite.OpenWeb())
{
SPWebApplication webApp = spWeb.Site.WebApplication;
webApp.FormDigestSettings.Enabled = false;
spWeb.AllowUnsafeUpdates = true;

// Content Type Updation Code
//CustomContentType.Update(True);

spWeb.AllowUnsafeUpdates = false;
webApp.FormDigestSettings.Enabled = true;
}
spSite.AllowUnsafeUpdates = false;
}
});