directory services group query changing randomly
- by yamspog
I am receiving an unusual behaviour in my asp.net application. I have code that uses Directory Services to find the AD groups for a given, authenticated user. The code goes something like ...
string username = "user";
string domain = "LDAP://DC=domain,DC=com";
DirectorySearcher search = new DirectorySearcher(domain);
search.Filter = "(SAMAccountName=" + username + ")";
And then I query and get the list of groups for the given user. The problem is that the code was receiving the list of groups as a list of strings. With our latest release of the software, we are starting to receive the list of groups as a byte[].
The system will return string, suddenly return byte[] and then with a reboot it returns string again.
Anyone have any ideas?
code sample:
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://" + ldapSearchBase);
DirectorySearcher userSearcher = new DirectorySearcher(dirEntry)
{ SearchScope = SearchScope.Subtree,
CacheResults = false,
Filter = ("(" + txtLdapSearchNameFilter.Text + "=" + userName + ")")
};
userResult = userSearcher.FindOne();
ResultPropertyValueCollection valCol = userResult.Properties["memberOf"];
foreach (object val in valCol)
{
if (val is string)
{
distName = val.ToString();
}
else
{
distName = enc.GetString((Byte[])val);
}
}