Feb
28
从LDAP读取记录,把edmworkstation和displayname这2项内容取出,放在一个dictionary中以备用.edmworkstation是用户的登记计算机名,可能含有多条记录.如果读取失败,则在dictionary中放一个"NotValid=yes"项目.
C# Code Copy Code To Clipboard
- 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;
- }
- }
Feb
25
Feb
25
有一个字符串,保存着一系列的机器名,要比较某个机器名是不是在这个字符串中, 此字符串以";"分隔,但是分号前后有可能会有空格. 先用SPLIT函数分割字符串,再用Array.IndexOf进行查找比较.
C# Code Copy Code To Clipboard
- string source = "a; ab; abc ; bc ;b";
- string unit = "bc";
- string[] sarray = source.ToLower().Split(new char[] {';',' '}, StringSplitOptions.RemoveEmptyEntries);
- return (Array.IndexOf<string>(sarray, unit.ToLower()) >= 0);



