Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Security validation for page is invalid

  Asked By: Gaurang    Date: May 28    Category: Sharepoint    Views: 1700

Setting web.TreeViewEnabled = true; on FeatureActivated Code throws exception
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.SetWebProps(String bstrUrl,
String .......................

The feature is stapled to site definition and I am replace default.aspx with a
custom file

public override void FeatureActivated(SPFeatureReceiverProperties properties)
SPWeb web = properties.Feature.Parent as SPWeb;
// Copy custom default.aspx file
SPFile file = web.GetFile("default.aspx");
if (file.Exists)
string pageUrl = web.Url + "default.aspx";
using (var manager = web.GetLimitedWebPartManager(pageUrl,
web.AllowUnsafeUpdates = true;
// Adds a custom web part and apply properties depending on the context
WebPart A = AddWebpart(web, manager, "XYZ.webpart", "Left", 1, string.Empty);

// And since I want Tree View Enabled by default, and this line actually throws
the error, // remove this line and code works like a charm
web.TreeViewEnabled = true;

web.AllowUnsafeUpdates = false;



No Answers Found. Be the First, To Post Answer.

Didn't find what you were looking for? Find more on Security validation for page is invalid Or get search suggestion and latest updates.