查询过滤器的ArgumentException试图延长OU校长时,过滤器、校长、ArgumentException、OU

2023-09-06 18:41:20 作者:地球是哥捏圆的

我尝试使用以下

[DirectoryRdnPrefix("OU")]
[DirectoryObjectClass("organizationalUnit")]
public class OrganizationalUnitPrincipal : Principal
{
    public OrganizationalUnitPrincipal(PrincipalContext Context_p)
    {
        PropertyInfo contextRaw = this.GetType().BaseType.GetProperty("ContextRaw",
            BindingFlags.Instance | BindingFlags.NonPublic);
        contextRaw.SetValue(this, Context_p, null);
    }
}

但它引发以下错误:

But it throws the following error:

System.ArgumentException: Persisted Principal objects cannot be used as query filters.

当我尝试检索组织单位的属性和属性会出现此错误。

This error occurs when I try retrieve organizationalUnit attributes and properties.

能否这项工作还是不?

我想达到相同的显示此网页。 http://msdn.microsoft上.COM / EN-US /网站/ bb384372

I want to achieve the same as show on this page http://msdn.microsoft.com/en-us/site/bb384372

推荐答案

在观的理论框架来看,我认为你想做的事是没有意义的。它在你点文章中解释,但它不是那么清楚。 主要的概念是基于 Directory架构至极discribe对象,您可以添加到ActiveDirectory中。

On the theorical point of view, I think that what you want to do has no sense. It's explained in the article you point, but it's not so clear. The concept of Principal is based on the Directory Schema wich discribe objects you can add to ActiveDirectory.

校长,AuthenticablePrincipal,UserPrincipal,ComputerPrincipal和GroupPrincipal类都可以扩展到创建扩展对象模型的自定义对象。

但是LDAP和一般它在活动目录的情况下,类组织单位不是用户的一个子类类,但类只是一个子类。

But in LDAP in general and it's the case in Active-Directory the class organizationalUnit is not a subclass of the user class, but just a subclass of the top class.

在换句话说:在视图概念点,你可以注意,主要是种用户(是在微软的角度来看计算机的用户,他们公开会议到像用户的域),并组织单位是一种组织盒的(如在一个文件系统中的目录),那么第二个不程度的第一个。

In other words : on the conceptual point of view you can note that a Principal is kind of user (Yes in Microsoft point of view computers are users, they open sessions onto the domain like the users) and organizationalUnit is a kind of organizational box (like a directory in a file system), so the second one do not extent the first one.

编辑

下面是的DirectoryEntry的子类,做你想做的:

Here is a subclass of DirectoryEntry that do what you want :

class ClsOrganizationalUnit : DirectoryEntry
{
  private DirectoryEntry de;

  public string Description
  {
    get { return (string)de.Properties["description"][0]; }
    set { de.Properties["description"].Value = value;
          de.CommitChanges();
        }
  }

  public ClsOrganizationalUnit(string dn, string username, string password)
  {
    de = new DirectoryEntry(dn, username, password);
  }


}

class Program
{
  static void Main(string[] args)
  {
    ClsOrganizationalUnit ou = new ClsOrganizationalUnit("LDAP://192.168.183.100:389/ou=Monou,dc=dom,dc=fr", "jpb", "pwd");

    /* Set the attribute */
    ou.Description = "The description you want";
    Console.WriteLine("Here is your OU description : {0}", ou.Description);

    /* Remove the attribute */
    ou.Description = null;
  }
}