I am trying to add three HTTP request filters to my applicationhost.config file using the below:
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
However, each subsequent line overrides the previous one and I can only add one line it seems. I want to add all three like this:
<verbs allowUnlisted="false">
<add verb="GET" allowed="true" />
<add verb="HEAD" allowed="true" />
<add verb="POST" allowed="true" />
</verbs>
All I end up with is the first GET
being written then HEAD
overriding the GET
and then POST
overriding the GET
...I just want all three listed.
Any ideas?
When you use the Set-WebConfigurationProperty
cmdlet, you effectively override the current value of the config section element in question.
If you want to append values to multi-valued properties, you should use Add-WebConfigurationProperty
instead:
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
If you want to make sure that only these three verbs exist in the collection, use Clear-WebConfiguration
before you add them:
Clear-WebConfiguration -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.