DirectorySearcher

G

Guest

Hi,
I have this code sample in my window application project :
DirectorySearcher mySearcher = new DirectorySearcher("(CN=WMLIN2)");
foreach( SearchResult resEnt in mySearcher.FindAll()) and it works
perfectly, it connecst to the domain and FindAll() function excutes perfectly
without any troubles.

I need run the same code in my ASP .Net web application and this wouldn't
work. FindAll() gives an exception that i can not connect to the domain or
might not exist. Any ideas why it works in wondows appl. but not asp.net. Any
ideas how to fix that?
 
M

Mark Rae [MVP]

I have this code sample in my window application project :
DirectorySearcher mySearcher = new DirectorySearcher("(CN=WMLIN2)");
foreach( SearchResult resEnt in mySearcher.FindAll()) and it works
perfectly, it connecst to the domain and FindAll() function excutes
perfectly
without any troubles.

I need run the same code in my ASP .Net web application and this wouldn't
work. FindAll() gives an exception that i can not connect to the domain or
might not exist. Any ideas why it works in wondows appl. but not asp.net.

Because the standard account under which ASP.NET runs does not (normally)
have sufficient privileges to query ActiveDirectory.
Any ideas how to fix that?

Two ways:

1) Use impersonation so that your web app runs under a different user
account which has access to Active Directory (recommended)

2) Supply explicit credentials to the DirectoryEntry constructor in the
System.DirectoryServices namespace
 

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,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top