powershell - 在 IIS Powershell 中添加 GET HEAD 和 POST 动词

标签 powershell iis

我正在尝试使用以下内容将三个 HTTP 请求过滤器添加到我的 applicationhost.config 文件中:

Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' -Value @{VERB="GET";allowed="True"} -Name collection
Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' -Value @{VERB="HEAD";allowed="True"} -Name collection
Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' -Value @{VERB="POST";allowed="True"} -Name collection

但是,随后的每一行都会覆盖前一行,而且我似乎只能添加一行。我想像这样添加所有三个:
        <verbs allowUnlisted="false">
            <add verb="GET" allowed="true" />
            <add verb="HEAD" allowed="true" />
            <add verb="POST" allowed="true" />
        </verbs>

我最终得到的是第一个 GET正在写入 HEAD覆盖 GET然后 POST覆盖 GET ...我只想列出所有三个。

有任何想法吗?

最佳答案

当您使用 Set-WebConfigurationProperty cmdlet,您可以有效地覆盖相关配置部分元素的当前值。

如果要将值附加到多值属性,则应使用 Add-WebConfigurationProperty反而:

Add-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering' -Value @{VERB="GET";allowed="True"} -Name Verbs -AtIndex 0
Add-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering' -Value @{VERB="HEAD";allowed="True"} -Name Verbs -AtIndex 1
Add-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering' -Value @{VERB="POST";allowed="True"} -Name Verbs -AtIndex 2

如果要确保集合中仅存在这三个动词,请使用 Clear-WebConfiguration在添加它们之前:
Clear-WebConfiguration -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' 

关于powershell - 在 IIS Powershell 中添加 GET HEAD 和 POST 动词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34617968/

相关文章:

iis - "Error 87 the all option is not recognised in this context"使用DISM启用IIS

google-chrome - Chrome 现在将 localhost 的 IP 地址视为与 somesite.localhost 相同

windows - 将 powershell 命令的输出分配给变量

powershell - 有没有办法在 PowerShell 中使用单个开关匹配来定位多个条件?

windows - 在 Windows 2012 R2 中使用 Powershell 导入计划任务

powershell - 如果任何其他进程使用,如何编写 powershell 脚本来释放文件

powershell - 忘记了 Raspberry Pi 2 的 Windows 10 IOT 密码

asp.net - 如何将 token 身份验证添加到我的 IIS 以保护文件夹中的文件?

包含 ";jsessionid="的 Apache URL 的 IIS 7 重定向

windows - 同时使用基本和集成身份验证