0

I am writing a small app that integrates with AD and will be listing users and allowing members of the site to edit certain fields of the users. These fields will be, first name, last name, display name and email.

When I run the following code I get an exception that says

The server is unwilling to process the request.

Please note that result is not null and contains the correct active directory user that I want to edit. Also note that result is of type SearchResult. Also note that the user I am using to connect to AD is the Administrative user.

DirectoryEntry entryToUpdate = result.GetDirectoryEntry();

entryToUpdate.Properties["cn"].Value = user.Name;
entryToUpdate.Properties["mail"].Value = user.Email;
entryToUpdate.Properties["sn"].Value = user.Surname;
entryToUpdate.Properties["displayName"].Value = user.DisplayName;

string username = user.Email.Substring(0, user.Email.IndexOf("@"));

entryToUpdate.Properties["sAMAccountName"].Value = username;

entryToUpdate.CommitChanges();

Any Ideas?

4

1 回答 1

0

I believe

entryToUpdate.Properties["cn"].Value = user.Name;

is your Problem. Use givenName as first Name. "cn" is managed by the System.

Also:
If using Exchange, the Mail attribute is managed by it.

Consider the ramifications of modifing samAccountName. Users may not know how to log in, seperate Systems with pseudo SSO may not recognize them, the Login Name does not match the local Profile Name, etc.

于 2013-04-24T17:50:37.393 回答