Query AD using Integrated Authentication?

From: Dave (Dave_at_discussions.microsoft.com)
Date: 07/27/04


Date: Tue, 27 Jul 2004 10:08:38 -0700

Hi,

I want to query AD for user's information once they are logged in.

Under Basic authentication, this worked fine using the code below.

However, when I switched to Integrated for an intranet site, the FindOne() bombs with "Logon failure: unknown user name or bad password". I don't know how to pass the username/password information while using Integrated Security. Is there a way to do this?

System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry("GC://mycompanydomain.com", HttpContext.Current.Request.ServerVariables["AUTH_USER"], HttpContext.Current.Request.ServerVariables["AUTH_PASSWORD"]);
System.DirectoryServices.DirectorySearcher search = new System.DirectoryServices.DirectorySearcher(entry);

search.Filter = "(sAMAccountName=" + sSAMAccountName + ")";
search.PropertiesToLoad.Add("sAMAccountName");
search.PropertiesToLoad.Add("cn");
search.PropertiesToLoad.Add("givenName");
search.PropertiesToLoad.Add("sn");
search.PropertiesToLoad.Add("mail");
search.PropertiesToLoad.Add("telephoneNumber");

System.DirectoryServices.SearchResult result = search.FindOne();