1. add reference System. directoryServices2.using System. directoryServices; [csharp] private static DirectoryEntry GetDirectoryObject () {DirectoryEntry entry = null; try {entry = new DirectoryEntry ("LDAP: // 192.168.10.5: 389/DC = ecera, DC = com, DC = tw "," customer "," 0511 @ sre ", AuthenticationTypes. secure);} catch (Exception ex) {} return entry;} [csharp] private void Form1_Load (object sender, EventArgs e) {Direct OryEntry entry = GetDirectoryObject (); DirectorySearcher search = new DirectorySearcher (entry); [csharp] view plaincopy // here the customer is the login account [csharp] search. filter = "(SAMAccountName =" + "customer" + ")"; try {SearchResult result = search. findOne (); if (result! = Null) {MessageBox. show ("successful"); MessageBox. show (result. path. toString () ;}} catch (Exception e1) {MessageBox. show (e1.Message) ;}} 3. note that LDAP of the AD connection string must be capitalized. Otherwise, an unknown error occurs. 4. an unknown user name or Password error occurs when the account and password used to log on to AD do not match. 5. The test passes normally in asp.net.