C # AD login verification

Source: Internet
Author: User
Tags ldap

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.