从本地网络上的活动目录读取用户的UserLoginName的问题. [英] problem to read UserLoginName of user from active directory on local network.
问题描述
嗨. Az,您知道在活动目录中定义的每个用户都具有FirstName,LastName,UserLoginName(sAMAccountName),Email,....现在,我具有本地网络上任何用户的FirstName + LastName,并且我想从中获取任何用户的UserLoginName服务器的活动目录.我该怎么办??这是我的代码::
Hi . Az you know every user that is defined in active directory has FirstName,LastName ,UserLoginName(sAMAccountName),Email,.... now i have FirstName+LastName of any users on my local network and i want to get UserLoginName of any users from server''s active directory.what can i do?? and here my code::
DirectoryServices.SearchResult myResult;
string filterString = string.Empty;
string EntryString = "LDAP:// MyDomain";
DirectoryServices.DirectorySearcher myDirectorySearcher = new DirectoryServices.DirectorySearcher(new DirectoryServices.DirectoryEntry(EntryString));
string tempStr;
string[] splStr = new string[3];
filterString = "CN="+FisrtAndLastNameOfUser;
myDirectorySearcher.Filter = filterString;
myDirectorySearcher.PropertiesToLoad.Add("UserName");
myResult = myDirectorySearcher.FindOne();
splStr = Regex.Split(myResult.Properties("UserName").Item(0).ToString, " ");
tempStr = splStr(1).ToString + " " + splStr(0).ToString;
Label1.Text = "Hello " + tempStr;
splStr=null;
的输出我哪里错了?非常感谢.
The output of splStr=null;
where is my wrong?? thanks a lot.
推荐答案
我看到的最明显的问题是,在调用DirectoryEntry
构造函数时,字符串参数中包含无效空格,即:
The most glaring problem I see is that in your call to theDirectoryEntry
constructor, the string parameter has an invalid space in it, namely:
"LDAP:// MyDomain"
应该是:
It should be:
"LDAP://MyDomain"
其次,您可能在字符串中缺少某些参数.我建议您在Google上搜索"C#DirectoryEntry",并使用您获得的546,000个示例之一.
Second, you may be missing some parameters inside the string. I recommend that you google "C# DirectoryEntry", and go with one of the 546,000 examples that you get back.
这篇关于从本地网络上的活动目录读取用户的UserLoginName的问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!