【问题标题】:Access is denied when start/stop Windows Service with ASP使用 ASP 启动/停止 Windows 服务时访问被拒绝
【发布时间】:2019-10-17 10:05:30
【问题描述】:

我编写了一个 ASP.NET Web 应用程序,它显示了我们产品的所有已安装服务。我的应用程序可以检索服务状态(正在运行、已停止...)。

此外,我的应用程序应该能够启动已停止的服务并停止正在运行的服务。在我的本地机器上它可以工作,在服务器上它不能。目前我将网络应用程序配置为使用管理员,但它没有启动。 事件查看器显示,访问被拒绝:

Process information: 
    Process ID: 5348 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL\ServiceManager 

Exception information: 
    Exception type: Win32Exception 
    Exception message: Access is denied



Request information: 
    Request URL: http://X/ServiceMonitor/StopService/25 
    Request path: /ServiceMonitor/StopService/25 
    User host address: X 
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: X\Administrator 

Thread information: 
    Thread ID: 23 
    Thread account name: X\Administrator 
    Is impersonating: False 
    Stack trace: 

知道我错过了什么吗?

作为附加信息,这里是我的 StartService 功能。但应该不是问题,因为它可以在我的本地机器上运行:

public bool StartService()
{
    ServiceController service = new ServiceController(_serviceName,_machineName);
    if (!new[] { ServiceControllerStatus.Running, ServiceControllerStatus.StartPending }.Contains(service.Status))
        service.Start();

    service.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMinutes(2));

    return service.Status == ServiceControllerStatus.Running;
}

【问题讨论】:

  • IIS APPPOOL\ServiceManager 你确定这个帐号有管理员权限吗?你在冒充吗?
  • @mason 我在哪里可以找到该帐户?这只是应用程序站点和应用程序池的名称。不是吗?在应用程序池中,我将用户设置为管理员
  • 好像应用程序池用户没有windows服务机器的管理员权限。
  • iis 用户或 iis 应用程序池没有足够的权限来启动或停止 windows 服务。所以你需要将 iusr、iis_iusrs 或 APPPOOL\ServiceManager 添加到 admin 组,这样你才能访问 windows 服务。这种方式很简单,但是不推荐的方式。另一种方法是您可以使用具有足够权限访问 Windows 服务并在 iis 应用程序池自定义帐户image 中设置的帐户。您可以在应用程序池高级设置下找到此设置。
  • @JalpaPanchal .. 我以为我已经这样做了(您在图像中显示的方式),但仍然是“ApplicationPoolIdentity”之类的。现在我改为管理员 - 并且繁荣,它工作:) 谢谢。也许将它添加为您的图像的答案 - 所以我可以接受它。

标签: asp.net iis windows-services access-denied servicecontroller


【解决方案1】:

iis 用户或 iis 应用程序池没有足够的权限来启动或停止 windows 服务。所以你需要将 iusr、iis_iusrs 或 APPPOOL\ServiceManager 添加到 admin 组,这样你才能访问 windows 服务。这种方式很容易,但不推荐的方式。另一种方法是您可以使用具有足够权限访问 Windows 服务并在 iis 应用程序池自定义帐户中设置的帐户。您可以在应用程序池高级设置下找到此设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-15
    • 2010-09-17
    • 2019-12-07
    • 1970-01-01
    相关资源
    最近更新 更多