hguser
hguser

Reputation: 36068

Access denied when get IIS DirectoryEntry in .net

When I tryo to create a new DirectEntry of IIS I always get the access denied,this is the code:

DirectoryEntry entry=new DirectoryEntry("IIS://localhost/W3SVC/1/ROOT");
foreach(DirectoryEnetry de in entry.Children){
 Console.WriteLine(de.Name);
}

The current user logined to the system has been the super administrator of the system.

So he should have all the permissions.

How to fix it?

BTW,I test the code in both asp.net web application and window form application,they all throw the same "access denied" exception.

Upvotes: 2

Views: 904

Answers (1)

Fandango68
Fandango68

Reputation: 4898

You need to provide the credentials of the LDAP server into your DirectoryEntry() object. Or, you need to make sure your Application Pool is referring to a Domain account and not NETWORKSERVICES or some other App Pool account, as they do not have access to AD.

i.e.

DirectoryEntry rootDSE = new DirectoryEntry("LDAP://yourldapserver");
rootDSE.Username = "user";
rootDSE.Password = "password";

Upvotes: 1

Related Questions