Getting E-Mail-Adress of User in a Web Service

S

Stefan Falk

Hello everybody,

the following code gets the e-mail address of an Active Directory account
when run inside a simple windows forms app:

Dim Query As String = "(SAMAccountName=TheAccountName)"
Dim Searcher As DirectorySearcher = New DirectorySearcher(Query, New
String() {"mail"})
Dim Result As SearchResult = Searcher.FindOne

However, running this inside an asp.net web service while impersonating the
calling user, which is logged on fine in active directory, Result is
nothing. Why?

Thanks in advance for a tip,
Stefan Falk
 
C

Chris S

I went through many exercises querying Active Directory using impersonation,
where it works with the default credentials, does not work with supplied
credentials, works with supplied credentials on the same machine as the WEB
service, etc, etc.
I ended up creating a DirectoryEntry object with a user name and password
(special user name and password created only to query Active Directory) as
parameters and construct the DirectorySearcher with the DirectoryEntry as
parameter. This is the only way I could get it to work consistent.
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top