简体   繁体   中英

C# Active Directory Library

Has anyone seen any solid libraries for working with active directory (mainly user related stuff) in C# and asp.net. Am I better off intergrating with asp membership or building something customised.

I took a look at LINQtoAD but it doesnt seem to be active anymore.

System.DirectoryServices程序集和命名空间是否不足?

If you're on .NET 3.5, also check out System.DirectoryServices.AccountManagement for much simpler interface when it comes to handling principals - users, groups, computers etc.

Check out this MSDN article as a great intro into S.DS.AD:

Managing Directory Security Principals in the .NET Framework 3.5

Cheers!

You can refer my OSS project which base on ActiveRecord pattern as following(Because it is open source you can find out how to operate the AD with DirectoryEntry, DirectoryEntry is not only support the LDAP protocol but also IIS, WIN and so on, so I develop this lib):

Eg: Update a user AD object.

using (var userObject = UserObject.FindOneByCN(this.ADOperator, “pangxiaoliang”))
{
     if(userObject.Email == "example@landpy.com")
     {
          userObject.Email = "mv@live.cn";
          userObject.Save();
     }
}

Eg: Query user AD objects.

// 1. CN end with "liu", Mail conatains "live" (Eg: mv@live.cn), job title is "Dev" and AD object type is user.
// 2. CN start with "pang", Mail conatains "live" (Eg: mv@live.cn), job title is "Dev" and AD object type is user.
            IFilter filter =
                new And(
                    new IsUser(),
                    new Contains(PersonAttributeNames.Mail, "live"),
                    new Is(PersonAttributeNames.Title, "Dev"),
                    new Or(
                            new StartWith(AttributeNames.CN, "pang"),
                            new EndWith(AttributeNames.CN, "liu")
                        )
                    );
// Output the user object display name.
foreach (var userObject in UserObject.FindAll(this.ADOperator, filter))
{
    using (userObject)
    {
        Console.WriteLine(userObject.DisplayName);
    }
}

Eg: Custom query.

IFilter filter =
    new And(
        new IsUser(),
        new Custom("(!userAccountControl:1.2.840.113556.1.4.803:=2)")
        );
// Output the user object display name.
foreach (var userObject in UserObject.FindAll(this.ADOperator, filter))
{
    using (userObject)
    {
        Console.WriteLine(userObject.DisplayName);
    }
}

https://landpyactivedirectory.codeplex.com/documentation

And you will find it easy to operate the AD with it, if you have no interest with it please ignore my answer. Any question about AD please contact me :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM