SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this code:

The EnsureUser Line is throwing me that exception, any idea?

The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.

 samAccountNames = GetSamAccountNamesToRemove(FindUsernames(membergroup), ppePeople2.GetSamAccountNames());


                            // Get the distinguished name for the usernames that should be removed from the (Member) AD Group and remove from the group
                            foreach (string username in samAccountNames)
                                string userdn = GetObjectDistinguishedName("user", username);

                                RemoveFromGroup(userdn, groupdn);

                                if (!string.IsNullOrEmpty(username))
                                    SPUser user = UpdateCurrentweb.EnsureUser(domain + "\\" + username);
                                    string group = "Member";
                                    int UserListID = UserAccessID(WorkspaceAccessList, user.Name, group);

                                    SPListItem item = WorkspaceAccessList.GetItemById(UserListID);
                                    UpdateCurrentweb.AllowUnsafeUpdates = true;
                                    UpdateCurrentweb.AllowUnsafeUpdates = false;
share|improve this question
Have you tried doing this with elevated permissions? – Ruben Herman Apr 3 '12 at 13:27
up vote 4 down vote accepted

Move the

UpdateCurrentweb.AllowUnsafeUpdates = true;

up before the call to EnsureUser. Maybe even further out depending on what RemoveFromGroup does.
There is no need to set it to false unless it's something like SPContext.Current.Web which is passed to other components

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.