I have an ASP .NET web application that is required to authenticate to and retrieve user lists from an Active Directory connection. The problem is the machine that is running the web server is part of a workgroup (NOT the domain that I am working with). I am able to authenticate to the AD by putting in the domain name but retrieving a user list is failing.
My question is, am I doing something wrong in trying to fetch AD users from outside the domain? If so, what can I do to rectify that? My code snippets are below:
public bool IsAuthenticated(string username, string pwd)
{
try
{
validUser = adContext.ValidateCredentials(username, pwd, ContextOptions.Negotiate);
}
catch (Exception ex)
{
Logging.Instance.Log(Logging.Levels.Error, "Error authenticating user: " + username + " : " + ex.Message.ToString());
}
return validUser;
}
public List<DirectoryEntry> GetAllUsers()
{
try
{
userADlist = new List<DirectoryEntry>();
Logging.Instance.Log(Logging.Levels.Message, "Finding all users for: "+adContext.ConnectedServer + " " + adContext.Container);
using (PrincipalSearcher searcher = new PrincipalSearcher(new UserPrincipal(adContext)))
{
foreach (Principal result in searcher.FindAll())
{
userADlist.Add(result.GetUnderlyingObject() as DirectoryEntry);
}
}
}
catch (Exception)
{
throw;
}
return userADlist;
}