LDAP directoryEntry

G

Guest

How do i create a directory entry to access a user's details such as their
email address. Here are the object structure.

domain.co.uk
|
|Computer Services - Type (OU)
|
|Cliff Saran - Type (User)

Cliff Saran's username is csaran, and here is what i am doing but it does
not work.

DirectoryEntry de = new DirectoryEntry("LDAP://CN=csaran,CN=User,
OU=Computer Services,DC=domain,DC=co,DC=uk");
string email = de.Properties["mail"].Value.ToString();
Response.Write(mail);

I get this message: There is no such object on the server

What am i doing wrong? many thanks in advance
 
G

Guest

I managed to get it working using CN=Cliff Saran rather than using CN=username.

How can i get it working using the username which i can grab from the user
login?

Basically i got a a function that gets the username from NT login, and i
want to use the username to grab their email address from the Active
Directory.
 
P

Patrick.O.Ige

What do tou really want to do?
What do you want to retrieve from the Active Directory?
Do you want to perform Authentication?




huzz said:
I managed to get it working using CN=Cliff Saran rather than using CN=username.

How can i get it working using the username which i can grab from the user
login?

Basically i got a a function that gets the username from NT login, and i
want to use the username to grab their email address from the Active
Directory.


huzz said:
How do i create a directory entry to access a user's details such as their
email address. Here are the object structure.

domain.co.uk
|
|Computer Services - Type (OU)
|
|Cliff Saran - Type (User)

Cliff Saran's username is csaran, and here is what i am doing but it does
not work.

DirectoryEntry de = new DirectoryEntry("LDAP://CN=csaran,CN=User,
OU=Computer Services,DC=domain,DC=co,DC=uk");
string email = de.Properties["mail"].Value.ToString();
Response.Write(mail);

I get this message: There is no such object on the server

What am i doing wrong? many thanks in advance
 
G

Guest

I want to grab the email address from a given username in AD

Patrick.O.Ige said:
What do tou really want to do?
What do you want to retrieve from the Active Directory?
Do you want to perform Authentication?




huzz said:
I managed to get it working using CN=Cliff Saran rather than using CN=username.

How can i get it working using the username which i can grab from the user
login?

Basically i got a a function that gets the username from NT login, and i
want to use the username to grab their email address from the Active
Directory.


huzz said:
How do i create a directory entry to access a user's details such as their
email address. Here are the object structure.

domain.co.uk
|
|Computer Services - Type (OU)
|
|Cliff Saran - Type (User)

Cliff Saran's username is csaran, and here is what i am doing but it does
not work.

DirectoryEntry de = new DirectoryEntry("LDAP://CN=csaran,CN=User,
OU=Computer Services,DC=domain,DC=co,DC=uk");
string email = de.Properties["mail"].Value.ToString();
Response.Write(mail);

I get this message: There is no such object on the server

What am i doing wrong? many thanks in advance
 
G

Guest

HUzz i guesss you can try this(to retrieve the usernames from the
ADirectory...)!
Paste this code below and play with the properties to search for what u are
looking for!
GDLUCK

<%
DirectoryEntry de = new DirectoryEntry("LDAP://urdomain/DC=urdomain, DC=com,
DC=au","ur_username","ur_passoword");

DirectorySearcher src = new
DirectorySearcher("(&(objectCategory=Person)(objectClass=user))");
src.SearchRoot = de;
src.SearchScope = SearchScope.Subtree;

foreach(SearchResult res in src.FindAll())
{
Response.Write(res.Properties["name"][0] + "<BR>");
}
%>

---------------------------------------------------

huzz said:
I want to grab the email address from a given username in AD

Patrick.O.Ige said:
What do tou really want to do?
What do you want to retrieve from the Active Directory?
Do you want to perform Authentication?




huzz said:
I managed to get it working using CN=Cliff Saran rather than using CN=username.

How can i get it working using the username which i can grab from the user
login?

Basically i got a a function that gets the username from NT login, and i
want to use the username to grab their email address from the Active
Directory.


:

How do i create a directory entry to access a user's details such as their
email address. Here are the object structure.

domain.co.uk
|
|Computer Services - Type (OU)
|
|Cliff Saran - Type (User)

Cliff Saran's username is csaran, and here is what i am doing but it does
not work.

DirectoryEntry de = new DirectoryEntry("LDAP://CN=csaran,CN=User,
OU=Computer Services,DC=domain,DC=co,DC=uk");
string email = de.Properties["mail"].Value.ToString();
Response.Write(mail);

I get this message: There is no such object on the server

What am i doing wrong? many thanks in advance
 
G

Guest

Or try this below:-(Hope it helps!!!)
private void DisplayUserDetails(string w2kLogin)
{
string adPath = "LDAP://dc=yourdomain,dc=com";
string qry = String.Format("(&
(objectCategory=person)(sAMAccountName={0}))", w2kLogin);
string[] attribs = new string[]
{"displayName", "mail"};

DirectoryEntry de = new DirectoryEntry
(adPath, null, null, AuthenticationTypes.Secure);
DirectorySearcher ds = new DirectorySearcher
(de,qry,attribs);

try
{
SearchResult sr = ds.FindOne();
if(sr != null)
{
foreach(string s in attribs)
{
if
(sr.Properties.Contains(s))

HttpContext.Current.Response.Write(s + ": " + sr.Properties
[0].ToString());
}
}
else

HttpContext.Current.Response.Write("User Not Found....");
}
catch(Exception ex)
{
string message;
if(ex.InnerException != null)
message =
ex.InnerException.Message;
else
message = ex.Message;
HttpContext.Current.Response.Write
(message);
}
finally
{
de.Close();
de.Dispose();
ds.Dispose();
}
}



huzz said:
I want to grab the email address from a given username in AD

Patrick.O.Ige said:
What do tou really want to do?
What do you want to retrieve from the Active Directory?
Do you want to perform Authentication?




huzz said:
I managed to get it working using CN=Cliff Saran rather than using CN=username.

How can i get it working using the username which i can grab from the user
login?

Basically i got a a function that gets the username from NT login, and i
want to use the username to grab their email address from the Active
Directory.


:

How do i create a directory entry to access a user's details such as their
email address. Here are the object structure.

domain.co.uk
|
|Computer Services - Type (OU)
|
|Cliff Saran - Type (User)

Cliff Saran's username is csaran, and here is what i am doing but it does
not work.

DirectoryEntry de = new DirectoryEntry("LDAP://CN=csaran,CN=User,
OU=Computer Services,DC=domain,DC=co,DC=uk");
string email = de.Properties["mail"].Value.ToString();
Response.Write(mail);

I get this message: There is no such object on the server

What am i doing wrong? many thanks in advance
 
G

Guest

HI Huzz..
I just tried doing this below and it works!!
Where the anr= Username
U can add more to the Mysearcher.properties.
Enjoy!

-------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim rootEntry As New DirectoryEntry("LDAP://urdomain/DC=UrDomain,
DC=com, DC=au", "username", "password")
Dim Mysearcher As New DirectorySearcher(rootEntry)

Mysearcher.PropertiesToLoad.Add("cn")

Mysearcher.PropertiesToLoad.Add("mail")

'searcher.PropertiesToLoad.AddRange(New String() {"cn", "mail"})

'would also work and saves you some code

Mysearcher.Filter =
"(&(anr=specify_the_username)(objectCategory=person))"

Dim Myresults As SearchResultCollection

Myresults = Mysearcher.FindAll()

Dim result As SearchResult

For Each result In Myresults

Response.Write("name=" + result.Properties("cn")(0) + "E-mail="
+ result.Properties("mail")(0) + "<br>")

Next
End Sub
-----------------------------------------------


huzz said:
I want to grab the email address from a given username in AD

Patrick.O.Ige said:
What do tou really want to do?
What do you want to retrieve from the Active Directory?
Do you want to perform Authentication?




huzz said:
I managed to get it working using CN=Cliff Saran rather than using CN=username.

How can i get it working using the username which i can grab from the user
login?

Basically i got a a function that gets the username from NT login, and i
want to use the username to grab their email address from the Active
Directory.


:

How do i create a directory entry to access a user's details such as their
email address. Here are the object structure.

domain.co.uk
|
|Computer Services - Type (OU)
|
|Cliff Saran - Type (User)

Cliff Saran's username is csaran, and here is what i am doing but it does
not work.

DirectoryEntry de = new DirectoryEntry("LDAP://CN=csaran,CN=User,
OU=Computer Services,DC=domain,DC=co,DC=uk");
string email = de.Properties["mail"].Value.ToString();
Response.Write(mail);

I get this message: There is no such object on the server

What am i doing wrong? many thanks in advance
 
Joined
Jan 13, 2010
Messages
3
Reaction score
0
Anonymously querying LDAP using .NET

Just in case anyone is looking to anonymously query LDAP with .NET - I could not get this to work, even with empty strings "" for the username and password. However, I happened to find the AuthenticationTypes.Anonymous option and that works for me!

So in case anyone is looking to query the LDAP anonymously, the DirectoryEntry declaration that worked for me is:

Dim oRoot As DirectoryEntry = New DirectoryEntry("LDAP://" & ldapServerName & "/dc=domainPart1,dc=domainPart2", "", "", AuthenticationTypes.Anonymous)

And a hearty Thank You to all that have helped me to this point!
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top