授予网络服务回收 iis 应用程序池的权限
我正在尝试创建一个 .NET Web 应用程序,用于重新启动远程 Web 服务器上的应用程序池,并在 Windows Server 2003 上运行 IIS 6.0。我的代码可以正常工作,但遇到权限问题。
string appPoolPath = ConfigurationSettings.AppSettings["ApplicationPool"];
string systemId = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
try
{
DirectoryEntry svc = new DirectoryEntry(appPoolPath);
svc.Invoke("Recycle");
LabelResult.Text = "Application Pool Recycled Succesfully!";
LabelResult.Visible = true;
}
catch(Exception exc)
{
LabelResult.Text = "Error (" + systemId + "): " + exc.Message + " : " + exc.InnerException;
LabelResult.Visible = true;
}
当我运行代码时,出现以下错误:
错误(NT AUTHORITY\NETWORK SERVICE):调用目标已引发异常。 :System.UnauthorizedAccessException:访问被拒绝。 (HRESULT 异常:0x80070005 (E_ACCESSDENIED))
所以我的问题是,如何授予 NETWORK SERVICE 帐户调用回收的权限,而不授予该帐户完整的管理权限?是否可以?
我知道解决此问题的另一种方法是模拟服务器上的现有管理员之一,但我不允许这样做。我无法在计算机上创建用户,也无法获取现有用户帐户的登录凭据。
I am trying to create a .NET web application that restarts an app pool on a remote web server, running IIS 6.0 on Windows Server 2003. I have the code working, but I have a permissions issue.
string appPoolPath = ConfigurationSettings.AppSettings["ApplicationPool"];
string systemId = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
try
{
DirectoryEntry svc = new DirectoryEntry(appPoolPath);
svc.Invoke("Recycle");
LabelResult.Text = "Application Pool Recycled Succesfully!";
LabelResult.Visible = true;
}
catch(Exception exc)
{
LabelResult.Text = "Error (" + systemId + "): " + exc.Message + " : " + exc.InnerException;
LabelResult.Visible = true;
}
When I run the code, I get the following error:
Error (NT AUTHORITY\NETWORK SERVICE): Exception has been thrown by the target of an invocation. : System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
So my question is, how can I grant the NETWORK SERVICE account permission to invoke recycle without giving the account full admin privileges? Is it possible?
I know another way to solve this is to impersonate one of the existing admins on the server, but I am not allowed to do that. I can't create users on the machine and I can't get login credentials for existing user accounts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另一种选择:
将虚拟文件放在 /bin 目录中,并在每次要重新启动池时更新它
Another option:
Put a dummy file in /bin directory, and update it everytime you want to restart the pool
这并不完全正确。
您需要 Web.Config 中的一个部分:
然后,当您修改 Test.config 时,应用程序池将被回收。
This is not entirely true.
You need a section in Web.Config:
Then when you modify Test.config, the app pool gets recycled.
尝试删除并创建应用程序池。已经解决了我的问题。
Try remove and create application pool. Has solved my problem.