System.DirectoryServices is not recognised in the namespace ‘System’
Right click on References under your solution. Select Add Reference. The reference can be found under the Framework Assemblies list. Select System.DirectoryServices and click Add.
Right click on References under your solution. Select Add Reference. The reference can be found under the Framework Assemblies list. Select System.DirectoryServices and click Add.
You can use the UserPrincipal class’ SetPassword method, provided you have enough privileges, once you’ve found the correct UserPrincipal object. Use FindByIdentity to look up the principal object in question. using (var context = new PrincipalContext( ContextType.Domain )) { using (var user = UserPrincipal.FindByIdentity( context, IdentityType.SamAccountName, userName )) { user.SetPassword( “newpassword” ); // or user.ChangePassword( … Read more
I’ve spent a lot of time analyzing the differences between these two. Here’s what I’ve learned. DirectorySearcher comes from the System.DirectoryServices namespace. PrincipalSearcher comes from the System.DirectoryServices.AccountManagement namespace, which is built on top of System.DirectoryServices. PrincipalSearcher internally uses DirectorySearcher. The AccountManagement namespace (i.e. PrincipalSearcher) was designed to simplify management of User, Group, and Computer objects … Read more
I had exactly the same error and fixed it by changing the site’s application pool to run under the Network Service. In IIS: Select your site’s application pool Select Advanced Settings on the right-hand side On the Advanced Settings pop-up window, scroll down to the Process Model group Change the first option called Identity to … Read more
You should use System.DirectoryServices.AccountManagement. It’s much easier. Here is a nice code project article giving you an overview on all the classes in this DLL. As you pointed out, your current approach doesn’t find out the primary group. Actually, it’s much worse than you thought. There are some more cases that it doesn’t work, like … Read more
I had the same again and again and nothing seemed to help. Changing the path from ldap:// to LDAP:// did the trick.
this code here should work… private bool IsActive(DirectoryEntry de) { if (de.NativeGuid == null) return false; int flags = (int)de.Properties[“userAccountControl”].Value; return !Convert.ToBoolean(flags & 0x0002); }