Wix MSI Installer:How 在 applicationHost.Config 中设置为 override="deny" 时允许匿名身份验证

Wix MSI Installer:How to allow anonymous authentication when set to override="deny" in applicationHost.Config

我有一个通过 Wix MSI 项目安装的 Web 应用程序。 web.config 包括以下身份验证节点。一切都安装正确,但安装后,我收到错误消息: "The configuration section cannot be used at this path"。这是由于 applicationHost.config 中的配置锁定。

<system.webServer>
    <security>
        <authentication>
            <anonymousAuthentication enabled="false" />
            <basicAuthentication enabled="true" />
            <windowsAuthentication enabled="false" />
        </authentication>
    </security>
</system.webServer>

如何在安装过程中覆盖 applicationHost.config 设置?我确实在安装过程中安装了必需的 Windows 功能,但我是否缺少一个功能?

这是对我有用的解决方案,在 InstallFinalize 之前从自定义操作调用 appcmd。

<CustomAction Id="UnlockAnonymousAuthentication"
             Execute="deferred"
             Impersonate="no"
             Return="check"
             Directory="TARGETDIR"
             ExeCommand="[SystemFolder]inetsrv\appcmd unlock config /section:anonymousAuthentication" />

<CustomAction Id="UnlockBasicAuthentication"
             Execute="deferred"
             Impersonate="no"
             Return="check"
             Directory="TARGETDIR"
             ExeCommand="[SystemFolder]inetsrv\appcmd unlock config /section:basicAuthentication" />

<CustomAction Id="UnlockWindowsAuthentication"
             Execute="deferred"
             Impersonate="no"
             Return="check"
             Directory="TARGETDIR"
             ExeCommand="[SystemFolder]inetsrv\appcmd unlock config /section:windowsAuthentication" />

<InstallExecuteSequence>
    <Custom Action="UnlockAnonymousAuthentication" Before="InstallFinalize"><![CDATA[NOT Installed]]></Custom>
    <Custom Action="UnlockBasicAuthentication" Before="InstallFinalize"><![CDATA[NOT Installed]]></Custom>
    <Custom Action="UnlockWindowsAuthentication" Before="InstallFinalize"><![CDATA[NOT Installed]]></Custom>
</InstallExecuteSequence>

希望这对某人有所帮助。

目前,这是一种使用 WiX IIS 扩展 WebDirProperties 元素直接执行此操作的方法:

https://wixtoolset.org/documentation/manual/v3/xsd/iis/webdirproperties.html

类似于此的东西应该可以工作。注意关键部分是 WebDirProperties 指定的元素 AnonymousAccess="yes" BasicAuthentication="no" WindowsAuthentication="no" 哪个修改 您希望在安装过程中更改的 IIS 属性。

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
 xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension" >

    <Fragment>

    <!-- Install to default web site -->
    <iis:WebSite Id="DefaultWebSite" Description='Default Web Site'>
      <iis:WebAddress Id="AllUnassigned" Port="80" />
    </iis:WebSite>


    <!-- References the installation folder specified in the Product.wxs file under the INSTALLFOLDER -->
    <DirectoryRef Id="WEB_INSTALLFOLDER">

      <!-- Configure virtual dir -->
      <Component Id="VirtualDirectoryComponent"
             Guid="{INSERT-YOUR-OWN-GUID-2C27-427A-A7B1-DA4DBCC79117}"
             KeyPath="yes" >
        <iis:WebVirtualDir Id="VirtualDirectory"
                  Alias="[WEB_DIRECTORY_ALIAS]" Directory="WEB_INSTALLFOLDER"
                  WebSite="DefaultWebSite">
          <iis:WebDirProperties Id="VirtualDirectoryProperties"
             AnonymousAccess="yes" BasicAuthentication="no"
             WindowsAuthentication="no" />
          <iis:WebApplication
             Id="MyWebApplication"
             Name="MyWebApplication" />
        </iis:WebVirtualDir>
      </Component>

    </DirectoryRef>

    </Fragment>

</Wix>