[英]System.DirectoryServices.Protocol search question
I'm trying to re write a search from System.DirectoryServices to System.DirectoryServices.Protocol 我试图将搜索从System.DirectoryServices重新写到System.DirectoryServices.Protocol
In S.DS I get all the requested attributes back, but in S.DS.P, I don't get the GUID, or the HomePhone... 在S.DS中,我获得了所有请求的属性,但是在S.DS.P中,我没有获得GUID或HomePhone ...
The rest of it works for one user. 其余的仅适用于一个用户。
Any Ideas? 有任何想法吗?
public static List<AllAdStudentsCV> GetUsersDistinguishedName( string domain, string distinguishedName )
{
try
{
NetworkCredential credentials = new NetworkCredential( ConfigurationManager.AppSettings[ "AD_User" ], ConfigurationManager.AppSettings[ "AD_Pass" ] );
LdapDirectoryIdentifier directoryIdentifier = new LdapDirectoryIdentifier( domain+":389" );
using ( LdapConnection connection = new LdapConnection( directoryIdentifier, credentials ) )
{
SearchRequest searchRequest = new SearchRequest( );
searchRequest.DistinguishedName = distinguishedName;
searchRequest.Filter = "(&(objectCategory=person)(objectClass=user)(sn=Afcan))";//"(&(objectClass=user))";
searchRequest.Scope = SearchScope.Subtree;
searchRequest.Attributes.Add("name");
searchRequest.Attributes.Add("sAMAccountName");
searchRequest.Attributes.Add("uid");
searchRequest.Attributes.Add("telexNumber"); // studId
searchRequest.Attributes.Add("HomePhone"); //ctrId
searchRequest.SizeLimit = Int32.MaxValue;
searchRequest.TimeLimit = new TimeSpan(0, 0, 45, 0);// 45 min - EWB
SearchResponse searchResponse = connection.SendRequest(searchRequest) as SearchResponse;
if (searchResponse == null) return null;
List<AllAdStudentsCV> users = new List<AllAdStudentsCV>();
foreach (SearchResultEntry entry in searchResponse.Entries)
{
AllAdStudentsCV user = new AllAdStudentsCV();
user.Active = "Y";
user.CenterName = "";
user.StudId = GetstringAttributeValue(entry.Attributes, "telexNumber");
user.CtrId = GetstringAttributeValue(entry.Attributes, "HomePhone");
user.Guid = GetstringAttributeValue(entry.Attributes, "uid");
user.Username = GetstringAttributeValue(entry.Attributes, "sAMAccountName");
users.Add(user);
}
return users;
}
}
catch (Exception ex)
{
throw;
}
}
Also, if I want to fetch EVERY user in AD, so I can synch data with my SQL DB, how do I do that, I Kept getting max size exceeded, errors. 另外,如果我想获取AD中的每个用户,以便可以与SQL DB同步数据,该怎么做,我一直无法获得最大大小,因此会出错。 I set the size to maxInt32... is there an "ignore size" option?
我将大小设置为maxInt32 ...是否有“忽略大小”选项?
Thanks, 谢谢,
Eric- 埃里克
I think that the standard way is to use System.DirectoryServices, not System.DirectoryServices.Protocol. 我认为标准方法是使用System.DirectoryServices,而不是System.DirectoryServices.Protocol。 Why do you want to user the later ?
为什么要稍后使用?
Concerning your second question about the error message "max sized exceeded", it may be because you try to fetch too many entries at once. 关于错误消息“超出最大大小”的第二个问题,可能是因为您尝试一次获取太多条目。
Active Directory limits the number of objects returned by query, in order to not overload the directory (the limit is something like 1000 objects). Active Directory限制了查询返回的对象数,以便不使目录超载(该限制类似于1000个对象)。 The standard way to fetch all the users is using paging searchs.
获取所有用户的标准方法是使用分页搜索。
The algorithm is like this: 算法是这样的:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.