check status application pool iis7 with csharp (access-denied)
Posted
by jack
on Stack Overflow
See other posts from Stack Overflow
or by jack
Published on 2010-04-27T17:19:42Z
Indexed on
2010/04/27
17:23 UTC
Read the original article
Hit count: 442
I need to monitor the status of an application in the applications pool of IIS 7 from an other machine on the same domain. My monitoring application must be in C# and running as a Windows service.
On my server, I create a user with administration rights and I execute the command aspnet_regiis -ga machine\username wich worked succesfully.
My problem is when I try to access the application pool i still get COMExcepttion "Access denied". What did i do wrong or wich step did i miss?
I used code from http://patelshailesh.com/index.php/create-a-website-application-pool-programmatically-using-csharp as example.
int status = 0;
string ipAddress = "10.20.2.13";
string username = "username";
string password = "password";
try
{
DirectoryEntry de = new DirectoryEntry(string.Format("IIS://{0}/W3SVC/AppPools/MyAppPoolName", ipAddress), username, password);
//the exception is thron here.
status = (int)de.InvokeGet("AppPoolState");
switch (status)
{
case 2:
//Runnig
break;
case 4:
//Stopped
break;
default:
break;
}
}
catch (Exception ex)
{
}
© Stack Overflow or respective owner