【问题标题】:In c# how do I set the active directy field "office" so i can show the location of our users in Outlook在 c# 中,如何设置活动目录字段“office”,以便我可以在 Outlook 中显示我们用户的位置
【发布时间】:2010-10-21 15:13:20
【问题描述】:

在 c# 中我试图设置办公室字段

当我这样做时:

ADEntry.Properties[ "office"].Add("Alaska");

它说办公室不存在。

谁能告诉我在这家酒店去哪里?

谢谢,

卡尔-

【问题讨论】:

    标签: c# .net active-directory


    【解决方案1】:

    经过长时间的研究,我得到了它..

    string Username = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Substring(System.Security.Principal.WindowsIdentity.GetCurrent().Name.IndexOf("\\") + 1);
    
     string office = string.Empty;
    
        using (var context = new PrincipalContext(ContextType.Domain, ConfigurationManager.AppSettings["DOMAIN"].ToString()))
        {
            using (var userPrincipal = new UserPrincipal(context))
            {
                userPrincipal.SamAccountName = Username;
    
                using (PrincipalSearcher search = new PrincipalSearcher(userPrincipal))
                {
                    UserPrincipal result = (UserPrincipal)search.FindOne();
    
                    DirectoryEntry directoryEntry = result.GetUnderlyingObject() as DirectoryEntry;
    
                    if (directoryEntry.Properties["physicalDeliveryOfficeName"].Count > 0
                            && directoryEntry.Properties["physicalDeliveryOfficeName"][0] != null
                            && !string.IsNullOrWhiteSpace(directoryEntry.Properties["physicalDeliveryOfficeName"][0].ToString()))
                    {
                        office = directoryEntry.Properties["physicalDeliveryOfficeName"][0].ToString();
                    }
                }
            }
        }
    

    【讨论】:

      【解决方案2】:

      查看Richard Mueller's web site - 他有大量关于 AD UI 中的哪些属性映射到 DirectoryEntry 上的基础 AD 属性的参考 Excel 表。

      您的具体“办公室”示例映射到 DirectoryEntry.Properties 集合中名为 physicalDeliveryOfficeName 的属性......

      【讨论】:

      • 谢谢!你的力量是强大的!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 2011-02-22
      • 2012-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多