Sharepoint 2010 通过LDAP中的完全匹配按id搜索用户(SharePoint 2010人员选取器)
我试图在LDAP中搜索一个用户,并在SharePoint PeoplePicker中解析他的名字 用户在PeoplePicker中键入用户的idsid,然后点击CheckName 代码使用类型化的userid调用SearchSingleUser() 示例:我键入“xyz”并点击CheckName 然后,下面的方法将使用SamAccountName='xyz'在LDAP中搜索用户以获得精确匹配。如果找到匹配项,则应在peoplepicker中解析idsid 如果LDAP具有域\xyz,但用户类型为xyz,则它将不匹配且无法解析 但我看到的是,这个名字已经解决了一半 有什么线索是我在寻找一个财产的精确匹配时遗漏的吗 这是我的代码:Sharepoint 2010 通过LDAP中的完全匹配按id搜索用户(SharePoint 2010人员选取器),sharepoint-2010,active-directory,ldap,Sharepoint 2010,Active Directory,Ldap,我试图在LDAP中搜索一个用户,并在SharePoint PeoplePicker中解析他的名字 用户在PeoplePicker中键入用户的idsid,然后点击CheckName 代码使用类型化的userid调用SearchSingleUser() 示例:我键入“xyz”并点击CheckName 然后,下面的方法将使用SamAccountName='xyz'在LDAP中搜索用户以获得精确匹配。如果找到匹配项,则应在peoplepicker中解析idsid 如果LDAP具有域\xyz,但用户类型为
public static string _LDAPSearchDefSingleUser = "(&(objectClass=user)(SamAccountName={0}))";
public static SearchResultCollection SearchSingleUser(string searchPattern)
{
using (DirectoryEntry root = new DirectoryEntry(ldapPath, username, password))
{
root.AuthenticationType = AuthenticationTypes.None;
string filter = string.Format(_LDAPSearchDefSingleUser, searchPattern);
using (DirectorySearcher searcher = new DirectorySearcher(root))
{
searcher.ReferralChasing = ReferralChasingOption.All;
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = filter;
searcher.PropertiesToLoad.Add("objectclass");
searcher.PropertiesToLoad.Add("SamAccountName");
SearchResultCollection results = searcher.FindAll();
return results;
}
}
}
不确定是否理解您的问题,但我确认以下过滤器:
(&(objectClass=user)(SamAccountName=xyz))
在LDAP中,搜索仅返回类user
的对象,其属性SamAccountName
完全等于“xyz”
在您的例子中,如果有多个匹配项,那是因为您输入了“*xyz”或“*xyz*”
供您参考,我使用了完全相同的代码,它也很有效。这对我来说很有效。我想要精确匹配,结果成功了。