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
Related posts:
- Repair broken Web Part Page in SharePoint / Remove Web Part From Page
- Make a SharePoint Application Page with CodeBehind
- Create Simple SharePoint Hello World WebPart And Add It To a Web Part Page
- Add A Web Part To NewForm.aspx, EditForm.aspx And DispForm.aspx (Edit Page missing in menu)
- Access SharePoint API from Console Program – Program Against the WSS Object Model
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.