如何在Active Directory中使用GUID(objectGUID)参数查找用户 [英] How I can find a User with the GUID(objectGUID) Parameter in Active Directory
问题描述
在我的ASP.NET应用程序中,我从Active Directory中获取信息.我必须通过GUID信息获得有关用户的信息(例如:a28a6a34dsfdsf57d9e54f945a241),但是我不知道如何在搜索中使用过滤器:/
In my ASP.NET Application I get Informations from Active Directory. I must get Informations about a User with the GUID Informations (example: a28a6a34dsfdsf57d9e54f945a241) but I don't know how I can use the filter right for this search :/
例如,如果我搜索用户姓氏:
for example if I search to a User Lastname:
DirectoryEntry Entry = new DirectoryEntry("LDAP://" + "Domain");
string filter = "(&(objectClass=user)(objectCategory=person)(cn=" + txtBenutzer.Text + "*))";
DirectorySearcher Searcher = new DirectorySearcher(Entry, filter);
var q = from s in Searcher.FindAll().OfType<SearchResult>()
select new
{
//GetProperty(s, "objectGUID"),
Benutzer = GetProperty(s, "sAMAccountName"),
eMail = GetProperty(s, "mail"),
Vorname = GetProperty(s, "givenName"),
Nachname = GetProperty(s, "sn"),
Telefon = GetProperty(s, "telephoneNumber"),
UserID = s.GetDirectoryEntry().NativeGuid
};
this.myListView.DataSource = q;
this.myListView.DataBind();
现在,我需要一个带有GUID的过滤器,以便可以在AD中找到一个唯一的用户.我在此搜索的GUID中包含一个字符串UserID = Session ["UserID"].toString()
now I need a filter with the GUID that I can find the one and only user in AD. The GUID for this Search I have in a string UserID = Session["UserID"].toString()
tarasov
推荐答案
您无需搜索,如果知道GUID,则可以直接绑定到对象,例如
You don't need to search, you can bind directly to the object if you know the GUID, e.g.
var user = new DirectoryEntry("LDAP://<GUID=119d0d80-699d-4e81-8e4e-5477e22ac1b3>");
(用实际的ObjectGUID代替).
(replace with your actual ObjectGUID).
检查此MSDN条目:使用ObjectGUID进行绑定到对象
Check this MSDN entry: Using ObjectGUID to Bind to an Object
这篇关于如何在Active Directory中使用GUID(objectGUID)参数查找用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!