Hello All,
I was facing an issue while creating the sub web under my current web, I was
getting a security validation exception. So I am discussing here the problem and
solution
Problem :
I was creating a sub web under my one of the web using following code and was
redirecting to new web
//Reference to current web
SPWeb spWeb =
SPContext.Current.Web;
//Getting all sub web collections
SPWebCollection
spSubWebCollections = spWeb.Webs;
//current template
string
currentTemplate = spWeb.WebTemplate;
string
siteUrl = txtSiteURL.Text;
string
siteTitle = txtSiteTitle.Text;
string
siteDescreption = txtSiteDescreption.Text;
//creating
sub web
SPWeb oNewWeb =
spSubWebCollections.Add(siteUrl, siteTitle, siteDescreption, 1033,
currentTemplate, false,
false);
Response.Redirect(oNewWeb.Url);
But I couldnt create new sub web, because I was getting the following error
Which is :
"The security validation for this page is invalid. Click Back in your Web
browser, refresh the page, and try your operation again. at
Microsoft.SharePoint.Library.SPRequestInternalClass.CreateWeb(String bstrUrl,
String bstrTitle, String bstrDescription, UInt32 nLCID, String bstrWebTemplate,
Boolean bCreateUniqueWeb, Boolean bConvertIfThere, Guid& pgWebId, Guid&
pgRootFolderId, Boolean bCreateSystemCatalogs) at
Microsoft.SharePoint.Library.SPRequest.CreateWeb(String bstrUrl, String
bstrTitle, String bstrDescription, UInt32 nLCID, String bstrWebTemplate, Boolean
bCreateUniqueWeb, Boolean bConvertIfThere, Guid& pgWebId, Guid& pgRootFolderId,
Boolean bCreateSystemCatalogs)"
Solution :
This error is because FormDiagest web control is missing on my page. So I have
added the FormDigest web control on my page and it worked.
<SharePoint:FormDigest
runat="server"
/>
FormDigest control inserts the security validation on the page.
Following is the referral link for the FormDigest control
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.formdigest.aspx