ad驗證

using System.DirectoryServices;

  DirectoryEntry dirEntry = new DirectoryEntry();
                    dirEntry.Path = "LDAP://IP/DC=;DC=;DC=;DC=";
                    dirEntry.Username = txtUser.Text;
                    dirEntry.Password = txtPassword.Text;
                    dirEntry.AuthenticationType = AuthenticationTypes.Secure;
                    DirectorySearcher search = new DirectorySearcher(dirEntry);
                    search.Filter = "(&(objectClass=user)(User=" + txtUser.Text + "))";
                    search.PropertiesToLoad.Add("SAMAccountName");
                    search.SearchScope = SearchScope.Subtree;
                    SearchResult result = search.FindOne();
                    using (SearchResultCollection results = search.FindAll())
                    {session["User"]=""; Response.Redirct();}

 

posted @ 2013-03-06 16:35  sirili  阅读(170)  评论(0编辑  收藏  举报