1

I have an MVC4 intranet page and would like to get the homeDireoctry attribute from Active Directory. would like to know the fastest way to get an attribute from AD.

found this link dated back to 2008, are there more efficient class avialable now rather than we code to query LDAP? Or other better ways? Is Linq to LDAP faster than this? please advise. Thanks.

Community
  • 1
  • 1
anIBMer
  • 1,159
  • 2
  • 12
  • 20

1 Answers1

2

The example from your link will work, but avoid using anr. It is a fuzzy search that hits multiple attributes (some of which may not be indexed). You most likely have the user name (I'm assuming since it's an intranet site) so use samaccountname instead and get the login from HttpContext.Current.User.Identity.Name. You can also get the information using the UserPrincipal class in System.DirectoryServices.AccountManagement:

UserPrincipal.Current.HomeDirectory;

If you plan to request more non-standard attributes from the directory it may be useful to use a more robust framework like LINQ to LDAP or LINQ to AD.

Alan
  • 456
  • 2
  • 9