简体   繁体   English

确保将 IIS AppPool 用户添加到 windows 组

[英]Ensure that IIS AppPool user is added to windows group

I am trying to deploy an ASP.NET application to IIS using Powershell (run by Ansible).我正在尝试使用 Powershell(由 Ansible 运行)将 ASP.NET 应用程序部署到 IIS。

I want my application to be able to query the performance counters so I am adding it to the Performance Monitor Users using this Powershell script:我希望我的应用程序能够查询性能计数器,因此我使用此 Powershell 脚本将其添加到性能监视器用户中:

appPoolName=$args[0]

$group = [ADSI]"WinNT://$Env:ComputerName/Performance Monitor Users,group"

$ntAccount = New-Object System.Security.Principal.NTAccount("IIS AppPool\$appPoolName")
$strSID = $ntAccount.Translate([System.Security.Principal.SecurityIdentifier])
$user = [ADSI]"WinNT://$strSID"

$group.Add($user.Path)

It actually comes from another SO question: Add IIS AppPool\\ASP.NET v4.0 to local windows group .它实际上来自另一个 SO 问题: Add IIS AppPool\\ASP.NET v4.0 to local windows group

After the deployment, it can happen that the user is added to the group but the application still can't access the performance counters.部署后,可能会发生将用户添加到组但应用程序仍然无法访问性能计数器的情况。

The script is run just before starting the App Pool and the application.该脚本在启动应用程序池和应用程序之前运行。 I have tried the following things, without success:我尝试了以下事情,但没有成功:

I have modified my deployment scripts in the following ways, without success:我通过以下方式修改了我的部署脚本,但没有成功:

  • Remove the user from the group before adding it在添加之前从组中删除用户
  • Restart the App Pool after adding the user.添加用户后重启应用池。 IIS actually complains ("The service cannot accept messages at this time"). IIS 实际上抱怨(“该服务此时无法接受消息”)。
  • Add the user to the group after starting the application启动应用程序后将用户添加到组中
  • Add the user to the group at the beginning of the deploy (before stopping the application and pool)在部署开始时将用户添加到组中(在停止应用程序和池之前)

The only way I have to solve my problem is to restart the machine.我必须解决我的问题的唯一方法是重新启动机器。 I would like to know if there is a better one!我想知道有没有更好的!

If it is possible, I think making the App Pool user log off and back on would solve my problem.如果可能,我认为让 App Pool 用户注销并重新登录可以解决我的问题。 I haven't found how to do that (restarting or recycling the App Pool doesn't work).我还没有找到如何做到这一点(重新启动或回收应用程序池不起作用)。

答案是一个简单的iisreset (在命令行或 Powershell 中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM