为新创建的IIS AppPool标识设置的权限

时间:2012-12-14 16:41:08

标签: iis-7 permissions wix

我需要为创建的IIS应用程序池的logs文件夹设置权限。设置权限的代码:

<CreateFolder Directory="SiteLogsFolder">
    <util:PermissionEx User="Everyone" Read="yes" GenericRead="yes"/>
    <util:PermissionEx User="[IisSiteUser]" GenericRead="yes" GenericWrite="yes" GenericExecute="yes" Delete="yes" DeleteChild="yes"/>
</CreateFolder>

<CustomAction Id="SetIis6SiteUser" Property="IisSiteUser" Value="NT AUTHORITY\NetworkService"/>
<CustomAction Id="SetIis7SiteUser" Property="IisSiteUser" Value="IIS AppPool\[SITE_APP_POOL]"/>

<InstallExecuteSequence>
  <Custom Action="SetIis7SiteUser" Before="InstallInitialize">IISMAJORVERSION>="#7"</Custom>
  <Custom Action="SetIis6SiteUser" Before="InstallInitialize">IISMAJORVERSION="#6"</Custom>
</InstallExecuteSequence>

这适用于Windows Server 2003上的IIS 6,但Windows Server 2008上的IIS 7.5无效。我收到错误:

ExecSecureObjects:  Error 0x80070534: failed to get sid for account: IIS AppPool\MyAppPool

调查详情:

  • 我也试过“IIS APPPOOL”域 - 结果相同。
  • 还尝试设置PermissionEx元素的Domain和User属性,而不是在User属性中合并它们。同样的错误。
  • 在PermissionEx中使用活动目录帐户可以正常工作。此外,活动目录帐户在设置时可以正常使用IIS站点池。
  • 如果我尝试为另一个AppPool设置权限(不是我的安装程序创建的权限,例如IIS AppPool \ DefaultAppPool),那么一切正常。仅当我为我的安装程序创建的AppPool设置权限时才会出现此问题。
  • 我检查了ConfigureIIs,SchedSecureObjects和ExecSecureObjects的排序,并尝试强制ConfigureIIs在其他两个之前执行(建议使用in this thread)。不幸的是,这也无济于事。

2 个答案:

答案 0 :(得分:3)

当我将我的WIX项目构建为x86时,我遇到了这个问题。我通过在ConfigureIIs之前调度Sc​​hedSecureObjects和ExecSecureObjects来解决它。

<Custom Action="SchedSecureObjects" After="ConfigureIIs" />
<Custom Action="ExecSecureObjects" After="ConfigureIIs" />

当我开始将项目构建为x64时,问题又出现了。这次我还必须在ConfigureIIs之前安排64位操作。

<Custom Action="SchedSecureObjects_x64" After="ConfigureIIs" />
<Custom Action="ExecSecureObjects_64" After="ConfigureIIs" />
<Custom Action="SchedSecureObjects" After="ConfigureIIs" />
<Custom Action="ExecSecureObjects" After="ConfigureIIs" />

答案 1 :(得分:2)

在Server 2012上进行测试,我确认在帐户可用之前可能会有延迟。使用以下脚本,我重新尝试了大约30次尝试中的3次失败。似乎我们需要在创建应用程序池和查找SID之间存在延迟。在我的测试中,它从未花费超过1秒。

param ($id)
if (!$id) {write-host "specify an id"; return}
c:\windows\system32\inetsrv\appcmd add apppool /name:$id /managedRuntimeVersion:"v4.0" /managedPipelineMode:"Integrated"
$objUser = New-Object System.Security.Principal.NTAccount("IIS APPPOOL\$id")
$sid=""
while (!$sid)
{
  $sid = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
  if (!$sid) {write-host "$id not found"} else {$sid}
  sleep 1
}