The “Error obtaining group names. An operations error occurred.” exception tends to occur when using Active Directory :
The probably fix for this would be get the group names by explicitly passing the security context.
Here is some sample code-
public string GetGroups(string domainName, string userName, string password)
{
String domainAndUsername = domainName + @"\" + userName;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, password);
StringBuilder groupNames = new StringBuilder();
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("memberOf");
SearchResult result = search.FindOne();
int propertyCount = result.Properties["memberOf"].Count;
String dn;
int equalsIndex, commaIndex;
for (int propertyCounter = 0; propertyCounter < propertyCount; propertyCounter++)
{
dn = (String)result.Properties["memberOf"][propertyCounter];
equalsIndex = dn.IndexOf("=", 1);
commaIndex = dn.IndexOf(",", 1);
if (-1 == equalsIndex)
{
return null;
}
groupNames.Append(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1));
groupNames.Append("|");
}
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
return groupNames.ToString();
}
Hope this helps
Cheers
0 Responses to "Error obtaining group names. An operations error occurred."
Post a Comment