How to use the objectGUID get a DirectoryEntry?

痴心易碎 提交于 2019-12-04 16:35:30

Without changing you code you've got multiple way to bind to Active-Directory. Here are two others ways :

The first one use GUID to bind to an object:

string conPath = "LDAP://10.0.0.6/<GUID=0b118130-2a6f-48d0-9b66-c12a0c71d892>";

The second one use SID to bind to an object:

string conPath = "LDAP://10.0.0.6/<SID=S-X-X-XX-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXX-XXX>"; 

Using security Principals you can do it like that :

UserPrincipal user = UserPrincipal.FindByIdentity(adPrincipalContext, IdentityType.DistinguishedName,"CN=User1Acct,OU=TechWriters,DC=wds,DC=gaga,DC=com");

or

UserPrincipal user = UserPrincipal.FindByIdentity(adPrincipalContext, IdentityType.Guid,"0b118130-2a6f-48d0-9b66-c12a0c71d892");

If .NET 3.5 is an option, you should start using System.DirectoryServices.AccountManagement. It is a whole new world. Here's is the code to find a user by the GUID:

using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, 
                                                  "LDAP://10.0.0.6", 
                                                  "DC=wds,DC=gaga,DC=com", 
                                                  "administrator", 
                                                  "Iampassword"))
{
    string theGuid = "0b118130-2a6f-48d0-9b66-c12a0c71d892";
    UserPrincipal up = UserPrincipal.FindByIdentity(pc, IdentityType.Guid, theGuid);
}

The same template would be easily adapted to other object types.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!