Is using DirectoryServices.NativeObject slow/bad?

2019-07-19 04:39发布

In an ASP.NET 4 application, I have existing code to access a user's Active Directory information (potentially under Windows Authentication or FBA) like this:

// 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();

It has always worked fine for me, on my LAN. But I get no feedback from customer sites (other than it works). I now note a post like http://www.justskins.com/forums/directoryentry-nativeobject-slow-with-203410.html, implying this COM way of going via DirectoryEntry.NativeObject might be inefficient or ill-advised? On the other hand, I see here LDAP search using DirectoryServices.Protocols slow, implying it is OK?

This code probably dates from .NET 1/2, when perhaps System.DirectoryServices had less in it; it came from some MS example for using ADSI somewhere.

In a word: I don't want to change the code just for the sake of it, but will if faster. Is there actually nowadays any superior method(s) in DirectoryServices which I should be using?

0条回答
登录 后发表回答