This is my code!
public static string ConnectAcitveDirectory(string groupName, string domainName, string serverName, string adminUserName, string queryUserName, string queryPassword)
{
try
{
using (PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, serverName, domainName + "\\" + queryUserName, queryPassword))
{
using (UserPrincipal foundUser = UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, adminUserName))
{
if (foundUser != null )
return "user found";
else
return "no user!;
}
}
}
catch (Exception ex)
{
return ex.ToString();
}
}
Both the above codes (commented and uncommented code) would work one at a time. They work in my local system, in a console application.
But if I move the console application's EXE file to a server, where Active Directory is installed, it would not work. Instead throws below error.
--------------------------------------------------------------------------------------
System.DirectoryServices.DirectoryServicesCOMException (0x8007052E): The user name or password is incorrect. at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_AdsObject() at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) at tap.dom.usr.Authentication.ConnectAcitveDirectory(String groupName, String domainName, String serverName, String adminUserName, String queryUserName, String queryPassword)
--------------------------------------------------------------------------------------
Any idea guys? Please let me know if you have any solution for this.
Thank you,
RelicV