System.DirectoryServices is slow?

后端 未结 2 1420
孤独总比滥情好
孤独总比滥情好 2021-01-13 15:28

I\'m using the code below to look up information in active directory when a user logs on to a website. Running against a local domain it\'s very quick, but running over a VP

相关标签:
2条回答
  • 2021-01-13 15:58

    I have never tried the scenario you are describing (connecting over VPN to Active Directory) but the line you marked is the line that causes the connection to be opened. You are not connected to the server before calling FindOne. My guess is that establishing the connection lasts 7-8 secs.

    If you cannot find exact answer on stackoverflow try this forum: http://directoryprogramming.net/forums/default.aspx (I'm not saying that stackoverflow is not helpful, but I found some answers to my ad/ldap questions on DirectoryProgramming.net forum).

    0 讨论(0)
  • 2021-01-13 16:05

    Another suggestion is to use System.DirectoryServices.Protocols directly; you code will look like:

    string filter = "(&(&(objectclass=user)(objectcategory=person))" + 
                    "sAMAccountName=username)";
    NetworkCredential credentials = new NetworkCredential(...);
    LdapDirectoryIdentifier directoryIdentifier = 
       new LdapDirectoryIdentifier("server", 389, false, false);
    using (LdapConnection connection = 
       new LdapConnection(directoryIdentifier, credentials, AuthType.Basic))
    {
        connection.Timeout = new TimeSpan(0, 0, 30);
        connection.SessionOptions.ProtocolVersion = 3;
        SearchRequest search = 
            new SearchRequest(query, filter, SearchScope.Base, "mail");
        SearchResponse response = connection.SendRequest(search) as SearchResponse;
        foreach(SearchResultEntry entry in response.Entries)
        {
            Console.WriteLine(entry.Attributes["mail"][0]);
        }
    }
    
    0 讨论(0)
提交回复
热议问题