【问题标题】:IIS 10 - Any way to set overrideMode="Allow" on website using powershell?IIS 10 - 使用powershell在网站上设置 overrideMode="Allow" 的任何方式?
【发布时间】:2020-11-18 21:43:16
【问题描述】:

我只需要在网站下的一个文件上允许“anonymousAuthentication”,但是将这些行添加到 web.config 告诉我我不能覆盖父设置。我查看了 applicationHost.config 的文档,如果我手动将 overrideMode="Allow" 添加到 location 行,它应该可以工作(并且确实可以)但我找不到如何使用 powershell 执行此操作(我们正在尝试编写整个事情的脚本通过ansible和powershell)

applicationHost 中的网站配置如下所示:

    <location path="mywebsite"> <-line should be <location path="mywebsite" overrideMode="Allow" >
        <system.webServer>
            <security>
                <authentication>
                    <anonymousAuthentication enabled="false" />
                    <windowsAuthentication enabled="true" />
                </authentication>
            </security>
        </system.webServer>
    </location>

我为单个文件尝试了 Set-WebConfigurationProperty,但它在 applicationHost 中创建了另一个部分来控制设置,这不是我们想要的,因为 web.config 保持锁定,所以未来的更改仍然必须在 applicationHost.config

有谁知道能不能做到?

编辑:更多信息:这是我们想要在 web.config 中工作的内容

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <add value="mainf.htm" />
            </files>
        </defaultDocument>
    </system.webServer>
    <location path="probe.txt">
        <system.webServer>
            <security>
                <authentication>
                    <anonymousAuthentication enabled="true" />
                    <windowsAuthentication enabled="false" />
                </authentication>
            </security>
        </system.webServer>
    </location>
</configuration>

【问题讨论】:

  • 没有用于操作锁定设置的 cmdlet。以管理员身份运行您的脚本并使用直接 XML 文件操作来编辑 applicationHost.config

标签: powershell iis


【解决方案1】:

我尝试了很多方法,但只有一个 powershell 语句有效。你可以试试看。

 Set-WebConfigurationProperty -filter /system.webServer/security/authentication -name 'sections["anonymousAuthentication"].OverrideModeDefault' -value Allow -pspath iis:\

【讨论】:

  • 这项工作,我还发现了另一个我将在下面列出的命令,但这也有效,因此将其标记为正确答案,谢谢 :)
【解决方案2】:

为了将来参考,这也有效:

Set-WebConfiguration -Filter //System.webServer/Security/Authentication/anonymousAuthentication -PSPath IIS:\Sites -location "Website" -Metadata overrideMode -Value Allow

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-24
    • 2012-12-23
    • 2018-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多