web service system.directoryservices call access denied

J

Jason Gleason

I am using the following method in a web service that utilizes the
system.directoryservices namespace:
[WebMethod]
public ArrayList GetAllAppPools(){
System.DirectoryServices.DirectoryEntry apppools = new
DirectoryEntry("IIS://webserver/W3SVC/AppPools");
ArrayList appPoolNames = new ArrayList();
foreach(DirectoryEntry de in apppools.Children)
{
appPoolNames.Add(de.Name);
}
return appPoolNames;
}

However, when i try to test the web service method, i get the following
error in the browser:

System.Runtime.InteropServices.COMException (0x80070005): Access is denied
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_IsContainer()
at System.DirectoryServices.ChildEnumerator..ctor(DirectoryEntry
container)
at System.DirectoryServices.DirectoryEntries.GetEnumerator()
at WebService1.Service1.GetAllAppPools() in
c:\inetpub\wwwroot\webservice1\service1.asmx.cs:line 86

We think it has something to do with security and ADSI, but we're not sure
how to fix it. Does anyone have any ideas? The code/dll works perfectly in a
windows form application. We will happily answer any further questions about
the problem. Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Jason,

You are right. By default, ASP.NET runs under the ASPNET local user
account, which has limited rights. Chances are your AD controller isn't set
up to allow access by that user (it doesn't have rights to the network
either).

To get around this, use the overload of the DirectoryEntry constructor
which takes a username and password as well, passing the username and
password of an account that has the appropriate rights to access the AD
controller.

Hope this helps.
 

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

Top