在ASP.NET 4应用程序中,我有现有代码来访问用户的Active Directory信息(可能在Windows身份验证或FBA下),如下所示:
// authType taken from run-time config file, default below
AuthenticationTypes authType = AuthenticationTypes.Secure;
string path = "LDAP://" + domain;
DirectoryEntry entry = new DirectoryEntry(path);
entry.AuthenticationType = authType;
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
// set search Filter/Properties etc. ..., nice and correctly
SearchResult result = search.FindOne();
在我的局域网上,它一直对我很好。但我没有从客户网站获得任何反馈(除了它的工作)。我现在注意到一个像http://www.justskins.com/forums/directoryentry-nativeobject-slow-with-203410.html这样的帖子,暗示这种COM通过DirectoryEntry.NativeObject
的方式可能效率低下或不明智?另一方面,我在这里看到LDAP search using DirectoryServices.Protocols slow,暗示它没问题?
此代码可能是从.NET 1/2开始的,当时System.DirectoryServices
可能少了;它来自一些在某处使用ADSI
的MS示例。
总之:我不想仅仅为了它而更改代码,但如果更快的话。现在是否真的有DirectoryServices
中我应该使用的任何优秀方法?