码迷,mamicode.com
首页 > Windows程序 > 详细

C# AD 验证登陆

时间:2016-08-05 15:52:02      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;  

using (DirectoryEntry adsEntry = new DirectoryEntry("LDAP://test.com", userName, password, AuthenticationTypes.Secure))
                {
                    using (DirectorySearcher adsSearcher = new DirectorySearcher(adsEntry))
                    {
                        adsSearcher.Filter = "(sAMAccountName=" + userName + ")";
                        try
                        {
                            SearchResult adsSearchResult = adsSearcher.FindOne();                            
                        }
                        catch (Exception ex)
                        {
                            // 用户名或密码错误
                            string strError = ex.Message;
                        }
                        finally
                        {
                            adsEntry.Close();
                        }
                    }
                }

 

C# AD 验证登陆

标签:

原文地址:http://www.cnblogs.com/lishidefengchen/p/5741202.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!