0

I am using LinqToLdap and tried to find all users from our AD by using the example provided by LinqToLdap. But with no success. First I tried to modify the Model to better fit our AD

[DirectorySchema("DC=corp,DC=intern", ObjectClass = "User")]
public class User : DirectoryObjectBase{
    [DistinguishedName]
    public string DistinguishedName { get; set; }

    [DirectoryAttribute("cn", ReadOnly = true)]
    public string CommonName { get; set; }

    [DirectoryAttribute]
    public string Title { get; set; }

    [DirectoryAttribute(StoreGenerated = true)]
    public Guid ObjectGuid { get; set; }

    [DirectoryAttribute(StoreGenerated = true)]
    public SecurityIdentifier ObjectSid { get; set; }

    [DirectoryAttribute("memberOf", ReadOnly = true)]
    public Collection<string> GroupMemberships { get; set; }
}

And query with

public class LinqToLdapProvider{
    private LdapConfiguration _cfg;
    public LinqToLdapProvider(string domain){
        _cfg = new LdapConfiguration();
        _cfg.ConfigurePooledFactory(domain)
                .MinPoolSizeIs(1)
                .MaxPoolSizeIs(50)
                .AuthenticateAs(new NetworkCredential("MyDomain.Username","MySecretPAssword"));
    }
    public void Query(){
        using (var context = new DirectoryContext(_cfg)) {
            context.Log = Console.Out;
            var user = context.Query<User>(); // I expected this to return all users
        }
    }
}

But as result I got a very huge list containing all Servers and other stuff... I tried to find more information within the documentation and tried to modify the DirectorySchema Attribbute of User class bit with no luck.

Here is the path that I tried to query where the users are the ones with the green strokes.

enter image description here

JJR
  • 773
  • 2
  • 13
  • 32

1 Answers1

1

You'll need to be more specific with your mapping. Either change your naming context to your user OU or add ObjectClass="User" ObjectCategory="Person" to your schema mapping. See this for more information.

Alan
  • 456
  • 2
  • 9