Needed help in Sharepoint.
Hi,
I have inherited a sharepoint web part from dotnet Asp.net 2.0 that is
displaying task list in MOSS site. It calls FindAll() to locate a specific security
group, and then enumerates through the group to retrieve the user's
display names.
*Very* intermittently this web part will throw an exception - either
"System.Runtime.InteropServices.COMException: The server is not operational" or,
sometimes, "The authentication mechanism is
unknown". When I say intermittently, I mean very intermittently - it is
fine 60% of the time. There doesn't seem to be any pattern to the
errors .
I am really hoping someone can help, this is proving very difficult to
fix as it is so irregular.
Code
private DirectorySearcher GetDirectoryObject()
{
DirectoryEntry oDE = new DirectoryEntry("LDAP://MYDOMAIN", "username", "pwd", AuthenticationTypes.Secure);
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = oDE;
return deSearch;
}
public string GetProperty(SearchResult searchResult, string PropertyName)
{
if (searchResult.Properties.Contains(PropertyName))
{
return searchResult.Properties[PropertyName][0].ToString();
}
else
{
return string.Empty;
}
}
public string GetDept(string username)
{
DirectorySearcher deSearch = GetDirectoryObject();
deSearch.Filter = "(&(objectClass=user)(SAMAccountName=" + username + "))";
deSearch.SearchScope = SearchScope.Subtree;
string UserDept = "";
foreach (SearchResult results in deSearch.FindAll())
{
UserDept = GetProperty(results, "userPrincipalName");
}
return UserDept;
}
|