Skip to content


The security validation for this page is invalid. Click Back in your Web browser…

When making a custom provisioner for a site template I got this error:
“The security validation for this page is invalid. Click Back in your Web browser…”

There is an easy way to avoid this.
This is some sample code:

 public override void Provision(SPWebProvisioningProperties props)
        {
            props.Web.ApplyWebTemplate("TESTDATABASE#0");
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite siteCollection = new SPSite(props.Web.Site.ID))
                {
                    using (SPWeb web = siteCollection.OpenWeb(props.Web.ID))
                    {
                        web.Title = props.Data;
                        web.Update();
                        //Create sts child sites
                        web.Webs.Add("Childsite1", "Child Site 1", "", 1033, "STS#1", false, false);
                        web.Webs.Add("Childsite2", "Child Site 2", "", 1033, "STS#1", false, false);
                    }
 
                }
            });
        }

This code failed for me. I then added AllowUnsafeUpdates and It worked well. You add it to both SPSite and SPWeb objects.

 public override void Provision(SPWebProvisioningProperties props)
        {
            props.Web.ApplyWebTemplate("TESTDATABASE#0");
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite siteCollection = new SPSite(props.Web.Site.ID))
                {
                    siteCollection.AllowUnsafeUpdates = true;                                        
                    using (SPWeb web = siteCollection.OpenWeb(props.Web.ID))
                    {
                        web.AllowUnsafeUpdates = True;
                        web.Title = props.Data;
                        web.Update();
                        //Create sts child sites
                        web.Webs.Add("Childsite1", "Child Site 1", "", 1033, "STS#1", false, false);
                        web.Webs.Add("Childsite2", "Child Site 2", "", 1033, "STS#1", false, false);
                    }
 
                }
            });
        }

This worked for me. If it does not work, read Ishai Sagis post regarding this

DeliciousDiggTwitterFacebookLinkedInTechNetStumbleUponNewsVineTechnorati FavoritesSlashdotMSDNShare

Related posts:

  1. Repair broken Web Part Page in SharePoint / Remove Web Part From Page
  2. Make a SharePoint Application Page with CodeBehind
  3. Create Simple SharePoint Hello World WebPart And Add It To a Web Part Page
  4. Add A Web Part To NewForm.aspx, EditForm.aspx And DispForm.aspx (Edit Page missing in menu)
  5. Access SharePoint API from Console Program – Program Against the WSS Object Model

Posted in SharePoint 2007.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.



Page optimized by WP Minify WordPress Plugin