c# - 无法从 Active Directory 中读取 Mobile # 字段
问题描述
我正在尝试连接到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;
}
解决方案
我认为您的问题是某些(大多数)属性默认情况下不会在对象上设置,它们仅在第一次设置值时才针对该对象存在。您需要更新代码以处理根本不存在的值,并假设这意味着它没有设置值。
您可以通过对特定用户运行查询来测试这一点,观察缺少该mobile
属性,然后向该字段添加一个值,然后将其删除。然后,您应该会看到该属性从那时起包含在该用户的列表中。
推荐阅读
- python - Apache/Wsgi - 在 CentOS 上从本地环境切换到 virtualenv 时出现问题
- amazon-ec2 - 从 ec2 实例连接 dynamodb 需要哪个 IAM 角色?
- c# - Quartz.net 3.4 - global.asax 中的开始工作不会触发
- javascript - 在加载时进行 jquery keyup 计算的最佳有效方法
- ios - AVPlayer HLS 直播 IOS
- iis - GCP 负载平衡器 502 服务器错误和“backend_connection_closed_before_data_sent_to_client”IIS 10
- java - @Formular 错误的解决方法
- batch-file - 批处理和如果错误
- angular - 如何将 matMenuTriggerFor 动态附加到 Angular 材质菜单中的 DOM 元素?
- sql - Excel 函数生成的 SQL 查询不起作用