我正在尝试使用以下命令向我的applicationhost.config文件添加三个HTTP请求过滤器:
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
但是,每个后续行都会覆盖前一行,我只能添加一行.我想像这样添加所有三个:
我最终得到的是第一个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'