【发布时间】:2019-03-21 06:39:21
【问题描述】:
我正在尝试连接到Active Directory (2003) 以更新出现在OutLook 通讯簿中的Mobile # 字段,如下图所示。
我可以使用下面的代码读取大部分字段,但找不到 otherTelephone、mobile、otherMobile 字段。是什么原因?
static void Main(string[] args)
{
Console.Write("Enter user : ");
String username = Console.ReadLine();
try
{
DirectoryEntry myLdapConnection = createDirectoryEntry();
DirectorySearcher search = new DirectorySearcher(myLdapConnection,);
search.Filter = "(sAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("title");
search.PropertiesToLoad.Add("street");
search.PropertiesToLoad.Add("department");
search.PropertiesToLoad.Add("mail");
search.PropertiesToLoad.Add("manager");
search.PropertiesToLoad.Add("telephoneNumber");
search.PropertiesToLoad.Add("otherTelephone");
search.PropertiesToLoad.Add("mobile");
search.PropertiesToLoad.Add("otherMobile");
SearchResult result = search.FindOne();
if (result != null)
{
DirectoryEntry entryToUpdate = result.GetDirectoryEntry();
Console.WriteLine("Current title : " + entryToUpdate.Properties["title"][0].ToString());
//Console.Write("\n\nEnter new title : ");
//String newTitle = Console.ReadLine();
//entryToUpdate.Properties["title"].Value = newTitle;
//entryToUpdate.CommitChanges();
//Console.WriteLine("\n\n...new title saved");
Console.ReadLine();
}
else Console.WriteLine("User not found!");
}
catch (Exception e)
{
Console.WriteLine("Exception caught:\n\n" + e.ToString());
}
}
static DirectoryEntry createDirectoryEntry()
{
// create and return new LDAP connection with desired settings
DirectoryEntry ldapConnection = new DirectoryEntry("abc.ca");
ldapConnection.Path = "LDAP://OU=staffusers,DC=leeds-art,DC=ac,DC=uk";
ldapConnection.AuthenticationType = AuthenticationTypes.Secure;
return ldapConnection;
}
【问题讨论】:
-
您能否解释一下“未找到”的含义,因为这些属性是标准 AD 属性。它们可能没有价值。您发布的屏幕截图对这些字段中的任何一个都没有价值。
-
@Ashigore 我确实为某些用户提供了这些属性的值,但故意截取了我没有这些值的用户的屏幕截图。
result变量的Properties属性不包含属性mobile、otherMobile、'otherTelephone. Some other standard attributes for some employees also don't have values, but they do appear in the Properties withnull` 或empty值。
标签: c# active-directory ldap directoryentry