Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > get user details from Active Directory

Reply
Thread Tools

get user details from Active Directory

 
 
=?Utf-8?B?RGFuIE5hc2g=?=
Guest
Posts: n/a
 
      10-11-2004
Hi

I've got the Username of the logged in user and domain with
Page.User.Identity.Name. It comes in as "domain\user".

Now, I want to query AD to get the users Firstname and Email address. Can
anyone point me in the direction of an article?

Cheers


Dan
 
Reply With Quote
 
 
 
 
=?Utf-8?B?c3Jpbmk=?=
Guest
Posts: n/a
 
      10-11-2004
hi nash,
you have it all here
http://www.c-sharpcorner.com/DirectoryServices.asp
HTH
srini

"Dan Nash" wrote:

> Hi
>
> I've got the Username of the logged in user and domain with
> Page.User.Identity.Name. It comes in as "domain\user".
>
> Now, I want to query AD to get the users Firstname and Email address. Can
> anyone point me in the direction of an article?
>
> Cheers
>
>
> Dan

 
Reply With Quote
 
 
 
 
Mike Newton
Guest
Posts: n/a
 
      10-11-2004
Use an LDAP search.

Here's the RFC: http://www.faqs.org/rfcs/rfc2254.html

Here are a couple of articles on how to use it:
http://www.wwwcoder.com/main/parenti...8/default.aspx
http://www.codeproject.com/csharp/ADTester.asp
http://www.codeproject.com/aspnet/adsi1.asp

This one isn't as detailed:
http://www.codeproject.com/vb/net/LDAP_Using_VBnet.asp

Just remember that your logical operators for the filter are in prefix
notation. A search would go something like (&(CN='Dog')(Name='Yada'))
for AND operations, (|...) for OR operations.

The particular AD property that has the user name, I've found, is
sAMAccountName. This may or may not be the same for you. You'll have
to split off the domain name in any case.




Dan Nash wrote:
> Hi
>
> I've got the Username of the logged in user and domain with
> Page.User.Identity.Name. It comes in as "domain\user".
>
> Now, I want to query AD to get the users Firstname and Email address. Can
> anyone point me in the direction of an article?
>
> Cheers
>
>
> Dan

 
Reply With Quote
 
=?Utf-8?B?RGFuIE5hc2g=?=
Guest
Posts: n/a
 
      10-11-2004
Thanks guys - all very helpful.

However, I'm now trying to get it working (VC#). Problem I'm getting is it
doesn't seem to recognise the System.DirectoryServices namespace?

It's not in the Intellisense lists, and if I just type it, it says it can't
find it. Any ideas?

Cheers

Dan

"Dan Nash" wrote:

> Hi
>
> I've got the Username of the logged in user and domain with
> Page.User.Identity.Name. It comes in as "domain\user".
>
> Now, I want to query AD to get the users Firstname and Email address. Can
> anyone point me in the direction of an article?
>
> Cheers
>
>
> Dan

 
Reply With Quote
 
Mike Newton
Guest
Posts: n/a
 
      10-11-2004
You need to add System.DirectoryServices as a reference.



Dan Nash wrote:
> Thanks guys - all very helpful.
>
> However, I'm now trying to get it working (VC#). Problem I'm getting is it
> doesn't seem to recognise the System.DirectoryServices namespace?
>
> It's not in the Intellisense lists, and if I just type it, it says it can't
> find it. Any ideas?
>
> Cheers
>
> Dan
>
> "Dan Nash" wrote:
>
>
>>Hi
>>
>>I've got the Username of the logged in user and domain with
>>Page.User.Identity.Name. It comes in as "domain\user".
>>
>>Now, I want to query AD to get the users Firstname and Email address. Can
>>anyone point me in the direction of an article?
>>
>>Cheers
>>
>>
>>Dan

 
Reply With Quote
 
Eddy Jawed Eddy Jawed is offline
Junior Member
Join Date: Jul 2009
Posts: 2
 
      06-02-2010
Hi guys,

Here is some simple code that if you pass the first and surname of the person, it will find ALL e-mails of people with that name, not just the first one.


Imports System.Diagnostics.Debug
Imports System.DirectoryServices

Public Function GetEmailAddress(ByVal FirstName As String, ByVal LastName As String)

Dim X As Integer
Dim search As DirectorySearcher = New DirectorySearcher()
search.Filter = "(&(givenName=" + FirstName + ")(sn=" + LastName+ "))"

Dim res As SearchResultCollection = search.FindAll()

For Each ItemRes As SearchResult In res

WriteLine(ItemRes.Properties("mail")(0).ToString() )
Next

End Function


Thanks

Eddy
 
Reply With Quote
 
Eddy Jawed Eddy Jawed is offline
Junior Member
Join Date: Jul 2009
Posts: 2
 
      06-02-2010
Also if you want to modify it to get other items belonging to the person in question, then simply call on another property.

I used "mail" property in ItemRes.Properties("mail")(0).ToString())

But there are other properties for given name, domain etc, whatever it is you need. Just play around with it for a bit.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASA server allows every user in Active Directory to get in! Richard Herb Cisco 4 02-14-2008 08:40 PM
Show Details/Hide Details link button =?Utf-8?B?Sm9l?= ASP .Net 1 03-13-2006 04:51 PM
Hi I have one web application and i want to get the number of users who are currently accessing the application. Also I want to get the user details of each user, which is stored in a database. How can I do this? Pls help. Getting No: and anu Java 11 05-12-2005 03:25 PM
Active Directory Search fails ("The directory service is unavailab ejcosta ASP .Net Security 2 10-08-2004 09:57 AM
Warning "Re: Your details" & "Re: My details" Joe Lee Computer Support 3 05-17-2004 05:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57