LDAP directoryEntry

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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
 
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
 
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
 
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
 
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
 
Back
Top