I'm implementing a LAD request using ASP.Net. I have this method that the first time it's called, works as a charm:
public static ADUser GetUser(string userName)
{
using (var context = new PrincipalContext(ContextType.Domain, ActiveDirectoryHelper.ApplicationDomain))
{
using (var searcher = new DirectorySearcher())
{
var internalUserName = userName.Replace("@" + ActiveDirectoryHelper.ApplicationDomain, "");
var filter = string.Format("(&(objectCategory=person)(objectClass=user)(anr={0}))", internalUserName);
searcher.Filter = filter;
var user = searcher.FindOne();
var adUser = MapToUserModel(user);
return adUser;
}
}
}
Afterward, it's throwning the following exception using exactly the same filter:
000004DC: LdapErr: DSID-0C0906E8, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db1