我正在尝试使用以下命令向我的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
Run Code Online (Sandbox Code Playgroud)
但是,每个后续行都会覆盖前一行,我只能添加一行.我想像这样添加所有三个:
<verbs allowUnlisted="false">
<add verb="GET" allowed="true" />
<add verb="HEAD" allowed="true" />
<add verb="POST" allowed="true" />
</verbs>
Run Code Online (Sandbox Code Playgroud)
我最终得到的是第一个GET被写入然后HEAD覆盖GET然后POST覆盖GET...我只想要所有三个列出.
有任何想法吗?
使用Set-WebConfigurationPropertycmdlet时,可以有效地覆盖相关配置节元素的当前值.
如果要将值附加到多值属性,则应使用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
Run Code Online (Sandbox Code Playgroud)
如果要确保集合中只存在这三个谓词,请Clear-WebConfiguration在添加之前使用:
Clear-WebConfiguration -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1548 次 |
| 最近记录: |