我正在尝试使用以下内容将三个 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/