I have to find a way how to use company Active Direcotries to Login users and I am not sure if there is a certain way to connect without admin credentials (as anonymous) - I need to only search for user if he exist in there.
I tried plenty of solutions but nothing worked yet. I am new to AD and ASP.NET (but I used to do programming in Java).
The code I've used so far is this from MSDN site:
DirectoryEntry entry = new DirectoryEntry(_path);
try
{
//Bind to the native AdsObject to force authentication.
object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(sAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
//Update the new path to the user in the directory.
_path = result.Path;
_filterAttribute = (string)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
return true;
Where path is variable with link to LDAP (LDAP:///rootDSE)
Main problem is that i am not alble to trace if i am correctly connected to AD. Result ends with null, but I am sure I use right credentials for testing.
Can anyone help or give advice
Thanks a lot