问题描述
在我的 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()
塔拉索夫
推荐答案
不需要搜索,知道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) 参数的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!