Why do I need to turn off security validation?
I'm working on buildi开发者_开发问答ng a webpart that creates a site, adds some lists based on user input, and sets the theme for the site. I can do this whole operation from a console app running on the server just fine, but when I do this from the webpart I get a secrutiy validation error when I try to set the theme. I can get around this by turning off security validation for the entire web app through central admin, but I'd rather not go down that route. This is currently what I'm running -
SPSecurity.RunWithElevatedPrivileges(delegate()
{
newWeb = web.Webs.Add(siteName, siteName, description, 1033, "STS#1", true, false);
newWeb.AllowUnsafeUpdates = true;
ReadOnlyCollection<ThmxTheme> managedThemes = null;
managedThemes = ThmxTheme.GetManagedThemes(newWeb.Site);
foreach (ThmxTheme theme2 in managedThemes)
{
if (theme2.Name == "oked")
{
theme2.ApplyTo(newWeb, true);
break;
}
}
});
I've tried several different flavors of this, but all with the same result. Thanks!
This can happen if you are doing update operation on GET request.
Did you check out this
http://blogs.technet.com/b/speschka/archive/2011/09/14/a-new-twist-on-an-old-friend-quot-the-security-validation-for-this-page-is-invalid-quot-in-sharepoint-2010.aspx
精彩评论