![Avatar of Tom Knowlton](https://filedb.experts-exchange.com/files/public/2021/7/4/1dedc081-f855-4998-9dc3-895cb79db1a2.png)
LDAP: "there is no such object on the server"
Trying to connect to an LDAP server, and I get this message back:
"there is no such object on the server"
Here is my current attempt via C# code:
the filter being passed into the method is:
uid=abc123
(replacing abc123 with an actual netid does work in a windows client I downloaded, but not in the code above)
I should also note that I WAS able to connect via a windows LDAP client found on the web here:
http://ldapadmin.sourceforge.net/
So the LDAP server is able to give me the information... there is a problem with my C# code or the way I am requesting the info.
"there is no such object on the server"
Here is my current attempt via C# code:
public XmlDocument GetLDAPInfo(string filter)
{
XmlDocument xd = new XmlDocument();
string domain = string.Empty;
string userName = string.Empty;
string passWord = string.Empty;
AuthenticationTypes at = AuthenticationTypes.SecureSocketsLayer;
StringBuilder sb = new StringBuilder();
//****Connecting to LDAP active directory
domain = @"LDAP://ldap.uits.uconn.edu";
userName = "uid=coop-faculty_adoptions,ou=accounts,dc=uconn,dc=edu";
passWord = "xxxxxxxxxxxxxxxxxxxx";
//Create the object necessary to read the info from the LDAP directory
DirectoryEntry entry = new DirectoryEntry(domain, userName, passWord, at);
Response.Write(entry.Properties.Count.ToString());
DirectorySearcher mySearcher = new DirectorySearcher(entry);
SearchResultCollection results;
mySearcher.Filter = filter;
try
{
results = mySearcher.FindAll(); //ERROR ... ENTERS CATCH BLOCK AFTER THIS LINE EXECUTES
if (results.Count > 0)
{
Response.Write(results.Count.ToString());
sb.Append("<Users>");
foreach (SearchResult resEnt in results)
{
sb.Append("<User>");
ResultPropertyCollection propcoll = resEnt.Properties;
foreach (string key in propcoll.PropertyNames)
{
foreach (object values in propcoll[key])
{
switch (key)
{
case "sn":
sb.Append("<surname>" + values.ToString() + "</surname>");
break;
case "cn":
sb.Append("<cn>" + values.ToString() + "</cn>");
break;
case "name":
sb.Append("<name>" + values.ToString() + "</name>");
break;
case "givenname":
sb.Append("<givenname>" + values.ToString() + "</givenname>");
break;
case "distinguishedname":
sb.Append("<distinguishedname>" + values.ToString() + "</distinguishedname>");
break;
case "member":
sb.Append("<member>" + values.ToString() + "</member>");
break;
case "initials":
sb.Append("<initials>" + values.ToString() + "</initials>");
break;
case "postalcode":
sb.Append("<postalcode>" + values.ToString() + "</postalcode>");
break;
case "l":
sb.Append("<location>" + values.ToString() + "</location>");
break;
case "c":
sb.Append("<c>" + values.ToString() + "</c>");
break;
case "mobile":
sb.Append("<mobile>" + values.ToString() + "</mobile>");
break;
case "homephone":
sb.Append("<homephone>" + values.ToString() + "</homephone>");
break;
case "title":
sb.Append("<title>" + values.ToString() + "</title>");
break;
case "co":
sb.Append("<co>" + values.ToString() + "</co>");
break;
case "st":
sb.Append("<state>" + values.ToString() + "</state>");
break;
case "mail":
sb.Append("<mail>" + values.ToString() + "</mail>");
break;
case "password":
sb.Append("<password>" + values.ToString() + "</password>");
break;
case "samaccountname":
sb.Append("<samaccountname>" + values.ToString() + "</samaccountname>");
break;
case "memberof":
sb.Append("<memberof>" + values.ToString() + "</memberof>");
break;
case "uid":
sb.Append("<userid>" + values.ToString() + "</userid>");
break;
case "description":
sb.Append("<description>" + values.ToString() + "</description>");
break;
}
}
}
sb.Append("</User>");
}
sb.Append("</Users>");
xd.LoadXml(sb.ToString());
return xd;
}
}
catch (Exception ex)
{
string msg = ex.Message;
}
sb.Append("<Users><User>None</User></Users>");
xd.LoadXml(sb.ToString());
return xd;
}
the filter being passed into the method is:
uid=abc123
(replacing abc123 with an actual netid does work in a windows client I downloaded, but not in the code above)
I should also note that I WAS able to connect via a windows LDAP client found on the web here:
http://ldapadmin.sourceforge.net/
So the LDAP server is able to give me the information... there is a problem with my C# code or the way I am requesting the info.
![Avatar of Tom Knowlton](https://filedb.experts-exchange.com/files/public/2021/7/4/1dedc081-f855-4998-9dc3-895cb79db1a2.png)
ASKER
I am sorry, but I do not understand what you are asking me to do.
I need to know why my code gets this error from the LDAP server:
"there is no such object on the server"
When the windows application can connect just fine:
http://ldapadmin.sourceforge.net/
I need to know why my code gets this error from the LDAP server:
"there is no such object on the server"
When the windows application can connect just fine:
http://ldapadmin.sourceforge.net/
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
![Avatar of Tom Knowlton](https://filedb.experts-exchange.com/files/public/2021/7/4/1dedc081-f855-4998-9dc3-895cb79db1a2.png)
ASKER
I tried making the change....it made no difference... same error still.
"there is no such object on the server"
"there is no such object on the server"
![Avatar of Tom Knowlton](https://filedb.experts-exchange.com/files/public/2021/7/4/1dedc081-f855-4998-9dc3-895cb79db1a2.png)
ASKER
It was something along these lines.
![Avatar of Tom Knowlton](https://filedb.experts-exchange.com/files/public/2021/7/4/1dedc081-f855-4998-9dc3-895cb79db1a2.png)
ASKER
NOTE:
Here is my final working code:
Here is my final working code:
public static bool PersonFoundInLDAPIsFacultyMember(string filter)
{
string domain = string.Empty;
string userName = string.Empty;
string passWord = string.Empty;
AuthenticationTypes at = AuthenticationTypes.SecureSocketsLayer;
StringBuilder sb = new StringBuilder();
//****Connecting to LDAP active directory
domain = @"LDAP://ldap.uits.uconn.edu/dc=uconn,dc=edu";
userName = "uid=coop-faculty_adoptions,ou=accounts,dc=uconn,dc=edu";
passWord = "you wish";
//Create the object necessary to read the info from the LDAP directory
DirectoryEntry entry = new DirectoryEntry(domain, userName, passWord, at);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
SearchResultCollection results;
mySearcher.Filter = filter;
bool facultymemfound = false;
try
{
results = mySearcher.FindAll();
if (results.Count > 0)
{
foreach (SearchResult resEnt in results)
{
ResultPropertyCollection propcoll = resEnt.Properties;
foreach (string key in propcoll.PropertyNames)
{
foreach (object values in propcoll[key])
{
switch (key)
{
case "uconnpersonaffiliation":
if (values.ToString() == "Professional Staff")
{
facultymemfound = true;
}
break;
default:
break;
}
}
}
}
}
}
catch (Exception ex)
{
}
return facultymemfound;
}
2. If you are using .Net 2.0 follow steps (as I have implemented for our website):
2.1. First create connection string in web.config:
Open in new window
where XXX stands for Domain Controller of AD ( Get it by typing echo % LOGONSERVER % in AD Computer's command prompt)
2.2. For AD Username and Password you have to use same that are used for logging in AD.
2.3. Use the following code for getting users from AD:
Open in new window
Hope it help you to get connected to AD. Let us know if unable to achieve objective.