I am trying to provision some users to update their email address in active directory (AD). I’m trying to achieve it using MembershipUser class. But getting ‘general access denied error’. Here’s my code:
string userName = "sathish";
System.Web.Security.MembershipUser userDetails = System.Web.Security.Membership.GetUser(userName);
if (userDetails != null)
{
userDetails.Email = "sathish@xyzee.com";
System.Web.Security.Membership.UpdateUser(userDetails); // getting access denied error here
}
My question is,
-
Do I need proper previleges to update email address to AD?
-
Do we have any attribute to verify my current access level?
-
Is it possible to impersonate privileges programmatically to update email address?
If you’re on .NET 3.5 and up, you should check out the
System.DirectoryServices.AccountManagement(S.DS.AM) namespace. Read all about it here:Managing Directory Security Principals in the .NET Framework 3.5
Basically, you can define a domain context and easily find users and/or groups in AD:
The new S.DS.AM makes it really easy to play around with users and groups in AD: