我想重新写从一个的System.DirectoryServices搜索System.DirectoryServices.ProtocolSystem.DirectoryServices.Protocol搜索问题
在S.DS我得到的所有请求的属性后面,但在S.DS .P,我没有得到GUID或HomePhone ...
它的其余部分适用于一个用户。
什么想法?
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;
}
}
另外,如果我想获取在广告的每个用户,这样我就可以用我的SQL数据库同步数据,我怎么做,我一直得到最大规模突破,错误。我将大小设置为maxInt32 ...是否有“忽略大小”选项?
感谢,
Eric-
改变“HOMEPHONE”到“HOMEPHONE”现在我回家的电话,但还是老样子没有GUID ...任何想法都能在这里找到,而不是“UID”叫什么名字? –
它应该是objectGUID –
要容易地找到属性名称(即使那些AD不会使用常规工具(如ldapbrowser)显示),您应该尝试使用ADSIEdit(DC上的adsiedit.msc)浏览目录 –