Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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());

                        try
                        {

                            // 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;
                                    item.Delete();
                                    UpdateCurrentweb.AllowUnsafeUpdates = false;
                                }
share|improve this question
    
Have you tried doing this with elevated permissions? experimentsincode.com/?p=127 –  Ruben Herman Apr 3 '12 at 13:27

1 Answer 1

up vote 3 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

 
discard

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.