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;

1 Answer 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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