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();}

 

你可能感兴趣的:(ad)