加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何使用objectGUID获取DirectoryEntry?

发布时间:2020-12-16 01:45:27 所属栏目:百科 来源:网络整理
导读:我知道,我们可以像这样得到一个DirectoryEntry: string conPath = "LDAP://10.0.0.6/DC=wds,DC=gaga,DC=com";string conUser = "administrator";string conPwd = "Iampassword";DirectoryEntry de = new DirectoryEntry(conPath,conUser,conPwd,Authenticat
我知道,我们可以像这样得到一个DirectoryEntry:

string conPath = "LDAP://10.0.0.6/DC=wds,DC=gaga,DC=com";
string conUser = "administrator";
string conPwd = "Iampassword";
DirectoryEntry de = new DirectoryEntry(conPath,conUser,conPwd,AuthenticationTypes.Secure);

我们可以像这样更改用户的密码:

DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = de;
deSearch.Filter = String.Format("sAMAccountName={0}","xumai");
SearchResultCollection results = deSearch.FindAll();
foreach (SearchResult objResult in results)
{
    DirectoryEntry obj = objResult.GetDirectoryEntry();
    obj.Invoke("setPassword",new object[] { "Welcome99" });
    obj.CommitChanges();
}

如果使用

string x = obj.Guid.ToString();;

我们可以得到用户的objectGUID“0b118130-2a6f-48d0-9b66-c12a0c71d892”

我怎么能改变它是密码基础这个objectGUID?

如何搜索用户群这个objectGUID表单“LDAP://10.0.0.6/DC=wds,DC=com”?

是否有任何方式过滤它?等strFilter =“(&(objectGUID = 0b118130-2a6f-48d0-9b66-c12a0c71d892))”;

希望得到你的帮助

谢谢.

解决方法

在不更改代码的情况下,您已经获得了 multiple way to bind to Active-Directory.以下是另外两种方式:

第一个use GUID to bind to an object:

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

第二个use SID to bind to an object:

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

使用security Principals你可以这样做:

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

要么

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读