【问题标题】:Grant Network Service permission to recycle iis app pool授予网络服务权限以回收 iis 应用程序池
【发布时间】:2011-08-28 23:56:33
【问题描述】:

我正在尝试创建一个 .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 帐户调用回收的权限?有可能吗?

我知道解决此问题的另一种方法是冒充服务器上的现有管理员之一,但我不允许这样做。我无法在计算机上创建用户,也无法获取现有用户帐户的登录凭据。

【问题讨论】:

    标签: c# asp.net iis-6 windows-server-2003


    【解决方案1】:

    另一种选择:

    在 /bin 目录中放置一个虚拟文件,并在每次要重新启动池时更新它

    【讨论】:

    • 重启应用,而不是应用池
    【解决方案2】:

    这并不完全正确。 您需要 Web.Config 中的一个部分:

    <section name="TestSection" restartOnExternalChanges="true" requirePermission="false" type="System.Configuration.AppSettingsSection, System.Configuration"/>
    
    <TestSection configSource="Test.config"></TestSection>
    

    然后,当您修改 Test.config 时,应用程序池会被回收。

    【讨论】:

      【解决方案3】:

      尝试删除并创建应用程序池。解决了我的问题。

      var server = new ServerManager();
      var pool = server.ApplicationPools.FirstOrDefault(q => q.Name == "MyPool");
      if (pool != null)
      {
          server.ApplicationPools.Remove(pool);
          server.CommitChanges();
      
          server.ApplicationPools.Add("MyPool");
          server.CommitChanges();
      }
      

      【讨论】:

        猜你喜欢
        • 2017-06-13
        • 1970-01-01
        • 2018-11-22
        • 2017-01-31
        • 2019-07-07
        • 2013-01-17
        • 2012-04-29
        • 1970-01-01
        • 2013-03-07
        相关资源
        最近更新 更多