0
我的任务是找到一种方法从网页重新启动应用程序池。 IIS由我们自己的IT部门托管,因此,如有必要,所有需要的安全设置都将被更改。如何正确使用Microsoft.Web.Administration从网页启动应用程序池?
我使用Microsoft.Web.Administration.dll,并试图为我的本地IIS(7.5):在
ServerManager serverManager = new ServerManager();
ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;
foreach (ApplicationPool applicationPool in applicationPoolCollection)
{
appPoolNames.Add(applicationPool.Name);
// If the applicationPool is stopped, restart it.
if (applicationPool.State == ObjectState.Stopped)
{
applicationPool.Start();
}
}
// CommitChanges to persist the changes to the ApplicationHost.config.
serverManager.CommitChanges();
如果我把这个逻辑在一个WinForm和运行的本地管理员,我的应用程序池本地IIS将启动。但是,如果我把同样的逻辑在网页时,出现错误,在错误这一行:
if (applicationPool.State == ObjectState.Stopped)
Exception: System.ComponentModel.Win32Exception: Access is denied
我认为这是出于安全的,但我已经给本地管理员用户到我的应用程序池。有没有办法在网页上实现这一点?