[英]check status application pool iis7 with csharp (access-denied)
我需要从同一域中的另一台机器监视 IIS 7 应用程序池中的应用程序状态。 我的监控应用程序必须使用 C# 并作为 Windows 服务运行。
在我的服务器上,我创建了一个具有管理权限的用户,并执行成功运行的命令aspnet_regiis -ga machine\\username
。
我的问题是当我尝试访问应用程序池时,我仍然收到 COMExcepttion“拒绝访问”。 我做错了什么或者我错过了哪一步?
我使用来自http://patelshailesh.com/index.php/create-a-website-application-pool-programmatically-using-csharp 的代码作为示例。
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 thrown here.
status = (int)de.InvokeGet("AppPoolState");
switch (status)
{
case 2:
//Running
break;
case 4:
//Stopped
break;
default:
break;
}
}
catch (Exception ex)
{
}
您找到的代码似乎适用于 IIS6。 也许您最好使用新的受支持的 IIS7 管理 API。 您可以首先调用ServerManager.OpenRemote来获取ServerManager对象。
您可能需要处理AuthenticationType ,从 2.0 开始的默认值是 Secure 但您可能需要设置 SSL。 此外,我已经看到来自帐户的访问被拒绝消息,其中“用户必须在下次登录时更改密码”被选中。
这在 Windows 7 和 Windows Server 2008 上运行良好(不幸的是不适用于 XP 和 2003 Server)。 我必须通过服务器管理器在 IIS 中添加管理服务角色才能启用远程连接。
这是一个关于如何获取应用程序池状态的简短示例。
public ObjectState State
{
get
{
ServerManager server = null;
ObjectState result = ObjectState.Unknown;
try
{
server = ServerManager.OpenRemote(address);
result = server.ApplicationPools[name].State;
}
finally
{
if (server != null)
server.Dispose();
}
return result;
}
}
感谢德里斯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.