I use a console application to write some test code:
/// <summary>
/// Returns AD information for a specified userID.
/// </summary>
/// <param name="ntID"></param>
/// <returns></returns>
public ADUser GetUser(string ntID)
{
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(cn={0})", ntID);
search.PropertiesToLoad.Add("mail");
search.PropertiesToLoad.Add("givenName");
search.PropertiesToLoad.Add("sn");
search.PropertiesToLoad.Add("displayName");
search.PropertiesToLoad.Add("userPrincipalName");
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
return new ADUser(result);
}
And this worked fine from the console app. However, when I moved it to an ASP.NET application, I received an error message about not knowing the correct domain.
Is there a trick I am missing for accessing AD when running on the ASPNET account?
EDIT: Passing just a LDAP://domain connection string isn't enough, as it wants an actual login/password. Because this runs on a local account on a machine, I'm not sure what AD L/P to use. Can I delegate the accessing users account to this somehow?
EDIT #2: When trying to use identity impersonation, I get a DirectoryServicesCOMException with: