Click here to Skip to main content
15,747,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m getting this.. when i run my code. suggest me i good reason for this ....

at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.PropertyValueCollection.PopulateList()
at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
at System.DirectoryServices.DirectorySearcher.get_SearchRoot()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindOne()
at FormsAuthAD.LdapAuthentication.GetGroups() in D:\Amit\New folder\New folder (3)\New folder (3)\New folder\FormsAuthAD\FormsAuthAD\LdapAuthentication.cs:line 80

my code are as:

public bool IsAuthenticated(string domain, string username, string pwd)
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);

//Bind to the native AdsObject to force authentication.
object obj = entry.NativeObject;

DirectorySearcher search = new DirectorySearcher(entry);

search.Filter = "(SAMAccountName=" + username + ")";


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;

public string GetGroups()
//DirectoryEntries searchRoot = new DirectoryEntries(_path);
DirectorySearcher search = new DirectorySearcher(_path);

search.Filter = "(cn=" + _filterAttribute + ")";

StringBuilder groupNames = new StringBuilder();


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));
catch(Exception ex)
throw new Exception("Error obtaining group names. " + ex.Message);
return groupNames.ToString();

1 solution

Seems a security problem.

Are you running a windows forms solution? Are you current process user in the same domain that you are trying to search?

Are you running an Asp.Net solution? Does your application pool user have permissions for the AD that you are trying to search?

Every authenticated user have rights for search the active directory.
Share this answer
Member 8959491 11-Feb-13 6:51am    
ya i m a currewnt process user ...and i m trying to do so ...
how can i fix it ...for security a app

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900