Here is the path. Is it corrrect?
"LDAP://companyname.org/OU=Office,DC=PDC,DC=companyname,DC=org"
Thanks,
public bool IsAuthenticatedUser(string domain, string userName, string
password)
{
//string domainAndUsername = domain + @"\" + userName;
string domainAndUsername = userName + "@" + domain;
// Connect to SHP AD from DirectoryEntry object
DirectoryEntry entry = new DirectoryEntry(_path,
domainAndUsername, password);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
// Get user from directory based on their login name
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + userName + ")";
search.PropertiesToLoad.Add("cn");
// If more than one entry is found, only return the first
entry. If no entry
// is found, return null
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;
}
// Retrieve the list of group that a user is a member of the AD
public string GetUserGroup()
{
DirectorySearcher search = new DirectorySearcher(_path);
search.Filter = "(cn=" + _filterAttribute + ")";
search.PropertiesToLoad.Add("memberOf");
StringBuilder groupNames = new StringBuilder();
try
{
SearchResult result = search.FindOne();
int propertyCount = result.Properties["memberOf"].Count;
String dn;
int equalsIndex, commaIndex;
groupNames.Append("|");
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 obtaining group names. " +
ex.Message);
}
return groupNames.ToString();
}