Validating a Active Directory User
To check for a user's existence in Active Directory, which one is the bet开发者_开发技巧ter .Net library to use?
System.Web.Security.ActiveDirectoryMembershipProvider
or
System.DirectoryServices
I'm using using System.DirectoryServices
and I feel it is the exact one to use. I do see there are similar features provided in here.
Please advise.
Since you're on .NET 4.0, you should check out the System.DirectoryServices.AccountManagement
(S.DS.AM) namespace. Read all about it here:
- Managing Directory Security Principals in the .NET Framework 3.5
- MSDN docs on System.DirectoryServices.AccountManagement
Basically, you can define a domain context and easily find users and/or groups in AD:
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");
if(user != null)
{
// do something here....
}
The new S.DS.AM makes it really easy to play around with users and groups in AD!
精彩评论