C# – “Access Denied” when trying to connect to remote IIS server – C#

asp.netcdirectoryservicesiisSecurity

I receive an "Access Deined" COMException when I try to connect to a remote IIS 6 server from my C# application that is running under IIS 5.1.

Any ideas? I am experiencing all the same issues with the original questions.

Update – 4/1/09

I found this solution (http://www.codeproject.com/KB/cs/Start_Stop_IIS_Website.aspx) that consists of a window application connecting to an IIS server to start and stop web sites. I am able to run it on my workstation and connect to the IIS server.

Ugh….why can I run this stand alone application but not my ASP.NET application?

Original

I receive an "Access Denied" COMException when I try to connect to IIS from a remote machine using the DirectoryEntry.Exist method to check to see if the IIS server is valid.

string path = string.Format("IIS://{0}/W3SVC", server);

if(DirectoryEntry.Exist(path))
{
    //do something is valid....
}

I am a member of an active directory group that has been added to the Administrators groups to the IIS server I am trying to connect to.

Has anyone experience this issue and know how to resolve it?

UPDATE:

@Kev – It is an ASP.NET application. Also, I can connect without an username and password to the remote server through IIS6 Manager.

@Chris – I am trying to connect to the remote server to display the number of virtual directorys and determine the .NET framework version of each directory. See this SO question.

@dautzenb – My ASP.NET application is running under IIS 5.1 trying to connect to an IIS 6 server. I can see fault audits in the security log for my local ASPNET account on the remote server. When I try to debug the application, I am running under my domain account and still get the Access is denied.

UPDATE 2:

@Kev – I was able to establish to create a DirectoryEntry object using the following overload:

public DirectoryEntry
(    
    string path,    
    string username,    
    string password
)

But, all of the properties contain a " threw an exception of type 'System.Runtime.InteropServices.COMException'" while I debug the app.

Also, the AuthenticationType property is set to Secure.

UPDATE 3:

The following two failure audit entries were in the remote IIS server's security event log every time I tried to establish a connection:

First event:

Event Category: Account Logon
Event ID: 680
Log attempt by: MICROSOFT_AUTHENTICATION_PACKAGE_V1_0
Logon account: ASPNET
Source Workstation:
Error Code: 0xC0000234

Second event:

Event Category: Logon/Logoff
Event ID: 529
Logon Failure:
Reason: Unknown user name or bad password
User Name: ASPNET
Domain: (MyDomain)
Logon Type: 3
Logon Process: NtLmSsp

Authentication Package: NTLM
Workstation Name: (MyWorkstationId)
Caller User Name: –
Caller Domain: –
Caller Logon ID: –
Caller Process ID: –
Transited Services: –
Source Network Address: 10.12.13.35
Source Port: 1708

Impersonation is set to true and the username and password are blank. It is using the ASPNET account on the remote IIS server.

Best Answer

If it is an identity problem, you could try setting your IIS 5.1 application to use Integrated Windows Authentication, and then add the following to you web.config on your IIS5.1 web site under system.web to enable impersonation.

<identity impersonate="true"/>
<authentication mode="Windows" />
Related Topic