【问题标题】:Correct way to detect active directory object is belong to user or group?检测活动目录对象的正确方法是属于用户还是组?
【发布时间】:2016-10-06 13:07:56
【问题描述】:

检测活动目录对象是否属于组或用户的正确方法是什么?以下是我在 C# 中的处理方式:

foreach (SearchResult sr in src)
{
   if (sr.Properties["objectclass"].Contains("person") && sr.Properties["objectclass"].Contains("user"))
   {
      // USER ?
   }
   if (sr.Properties["objectclass"].Contains("group"))
   {
      // GROUP ?
   }
}

【问题讨论】:

  • 你的方式可以很好(不是objectClass吗?)。 OU 的 CN 是:objectClass organizationsUnit 一个人的 CN 是:objectClass person 一个组的 CN 我们:objectClass group 另一种方法可能是组织您的 AD,如果您检索 DirectoryEntry 的路径,您知道它是一个组或用户

标签: c# active-directory directoryservices


【解决方案1】:
if (sr != null)
{
    if(sr.Properties["objectCategory"] != null)
    {
       // objectType will be "Person" or "Group" (or something else entirely)
       string objectType = sr.Properties["objectCategory"][0].ToString();
       if (objectType == "Person")
       { 
          //It's a user
       }
       if (objectType == "Group")
       { 
          //It's a Group
       }
    }
}

检索自:How to determine the type (AD User vs. AD Group) of an account?

【讨论】:

  • 我实际上想确定已删除对象的对象类型,因为删除对象时会删除 objectCategory 属性。我问了新问题question link
猜你喜欢
  • 1970-01-01
  • 2018-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-03
  • 2011-07-16
相关资源
最近更新 更多