To retrieve data from ActiveDirectory I used the following code:
SPSecurity.RunWithElevatedPrivileges(delegate()
(
var currentDirectory = new DirectoryEntry(domainAddress);
));
But changing a property's value and attempt to update the values in ActiveDirectory (function CommitChanges()
) generates System.UnauthorizedAccessException Message = Access is denid
, because code execution carried out under the account NetworkService.
I tried to use the following code to run from the current user:
using (WindowsIdentity.GetCurrent().Impersonate ())
{
DirectoryEntry entry = new DirectoryEntry(domainAddress);
...
}
To run code from the current user, but continued use is generated DirectoryServicesCOMException, while user authentication is a protocol NTML. Prompt please, how is it possible to change the attributes of users in ActiveDirectory from the current user without requiring a password?