(&(objectClass = user)(|(&(SAMAccountName = jdoe *)))搜索过滤器是 无效。
我试图通过用户名jdoe找到John Doe的用户帐户。我使用了此搜索字符串的多个变体,它们都返回此错误。我究竟做错了什么?我是这样构建的:
var deSearch = new DirectorySearcher(de);
deSearch.Filter = string.Format("(&(objectClass=user)(|(&(SAMAccountName={0}*)))", uname);
SearchResult result = deSearch.FindOne();
答案 0 :(得分:3)
您需要关闭左括号:
(&(objectClass=user)(|(&(SAMAccountName=jdoe*))))
答案 1 :(得分:3)
如果您使用的是.Net 3.5或更高版本,则可以使用UserPrincipal对象来获取用户信息,如下所示。
PrincipalContext pcontext = new PrincipalContext(ContextType.Domain, domainName);
UserPrincipal user = UserPrincipal.FindByIdentity(pcontext,IdentityType.SamAccountName, "UserName");