Pages

Monday, July 20, 2009

Error while updating SharePoint list, “The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again”

This error "The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again" is very common for beginners SharePoint developer, who start developing and digging into SharePoint object model, it’s coming while updating SharePoint list, the cause of error is due to security rights, if we make web.AllowUnsafeUpdates = true and then update the SharePoint list then we won’t get above error.

Sample Code:

Web.AllowUnsafeUpdates = true;
item["Title"]=”Sample”;
item.Update();

Happy Coding !!

2 comments:

  1. you are opening holes to Cross scripting attacks by doing that... as mentioned in the blog from u got the code.. u need to set it back

    web.AllowUnsafeUpdates = false

    ReplyDelete
  2. Hey Sandeep,

    You are absolutely correct, we need to again set the value to FALSE after performing our update operation.

    Thank you very much for your comment.

    -Sanket

    ReplyDelete