LDAP Connection with ASP .Net

G

Guest

Hello
I'm developping an web application using ASP.Net and I Want that when i write a name i a textbox, the program give me personnals informations stored in LDAP... But i don't know if is it possible and who do that! so i explain what i did.. but it dont works :

First, i create a new C# project with ASP . Net web application.
I add System.DirectoryService reference.
In the WebForm, i put a textbox (id=nom) and a submit button (id=buton).

In the WebForm.aspx.cs, on the clic event i put this function :

********************
private void Button_Click(object sender, System.EventArgs e)
{
SearchResultCollection results = Client.SearchUser(nom.Text);
foreach(SearchResult result in results)
{
Response.Write("Nom de l'utilisateur" + result.Properties["cn"][0]);
Response.Write(result.Properties["title"][0]);
Response.Write(result.Properties["department"][0]);
Response.Write(result.Properties["physicalDeliveryOfficeName"][0]);
Response.Write(result.Properties["telephoneNumber"][0]);
}
}

*****************

And at last, i created a new class, name "client", and i white that :

***************
using System.DirectoryServices ;
using System ;

public class Client
{
static public SearchResultCollection SearchUser(string name)
{
DirectoryEntry root = new DirectoryEntry("ldap://ldap.baylor.edu/ou=Other,ou=People,o=Baylor University,c=US");
DirectorySearcher searcher=new DirectorySearcher(root);
searcher.Filter = "(anr=" + name + ")";
searcher.PropertiesToLoad.Add("cn");
searcher.PropertiesToLoad.Add("title");
searcher.PropertiesToLoad.Add("department");
searcher.PropertiesToLoad.Add("physicalDeliveryOfficeName");
searcher.PropertiesToLoad.Add("telephoneNumber");
return (searcher.FindAll());
}

public static void Main()
{
string[] args = Environment.GetCommandLineArgs();
string name = args[1];
}
}

_______________________________________________

But this code don't run :
on the button clic an error append
*******
On the class Client, at line 16 "return (searcher.FindAll());"

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Unknown error (0x80005000)
*****

I don't know who to do that! and I hope you will able to help me.
Thanks for all post ! by

PS : Sorry for my english !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top