Tuesday, April 20, 2010

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

While i was developing certain Sharepoint MOSS 2007 maintenance stuff I received the following error:

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

I developed the code against MOSS API and not on the website and was a kind of irritated about it!

The solution to solve this can be one of the following ways:

Option A)
turn off the security validation over your central administration:
- Central Administration
- Application Management
- Web Application Aettings
- "turn security validation off"

Option B)
You can modify the setting also within you coding:

SPSecurity.RunWithElevatedPrivileges(new SPSecurity.CodeToRunElevated(
delegate()
{
using (SPSite oSite = new SPSite("http://your.website.com/"))
{
using (SPWeb web = oSite.OpenWeb())
{
SPWebApplication webApp = web.Site.WebApplication;
webApp.FormDigestSettings.Enabled = false;
web.AllowUnsafeUpdates = true;


web.AllowUnsafeUpdates = false;
webApp.FormDigestSettings.Enabled = true;
web.close();
}
}
}
)
);

1 comment:

Rizwan Ansari said...

There is one more reason that will cause this issue. You may have to use SPUtility.ValidateFormDigest() just before elevating the code. I have discussed this in my post http://sharepointtechie.blogspot.com/2011/02/solution-security-validation-for-this.html
Please do update me with your comments.

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.

Facebook Badge