从LDAP读取记录,把edmworkstation和displayname这2项内容取出,放在一个dictionary中以备用.edmworkstation是用户的登记计算机名,可能含有多条记录.如果读取失败,则在dictionary中放一个"NotValid=yes"项目.
- private void GetLDAPInfo()
- {
- try
- {
- DirectoryEntry entry = new DirectoryEntry("LDAP://ldap.xxx.com/o=xxx,c=an");
- entry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
- DirectorySearcher searcher = new DirectorySearcher(entry);
- searcher.Filter = "(alias=" + getLoginName() + ')';
- SearchResult result = searcher.FindOne();
- if (result == null)
- {
- LDAPInfo.Add("NotValid", "yes");
- errnum = -40;
- return;
- }
-
- string path = result.Path;
- path = path.Substring(path.LastIndexOf("/") + 1);
- ResultPropertyCollection p = result.Properties;
-
- string v = "";
- if (p.Contains("edmworkstation"))
- {
- foreach (var a in p["edmworkstation"])
- {
- v += a.ToString().Substring(0, a.ToString().IndexOf('/')) + ";";
- }
- LDAPInfo.Add("pcnames", v);
- }
- else
- {
- LDAPInfo.Add("NotValid", "yes");
- }
-
- if (p.Contains("displayName"))
- {
- v = "";
- foreach (var a in p["displayName"])
- {
- v += a.ToString();
- }
- LDAPInfo.Add("displayname",v);
- }
- }
- catch
- {
- LDAPInfo.Add("NotValid", "yes");
- errnum = -40;
- return;
- }
- }