Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding GET HEAD and POST Verbs in IIS Powershell

Tags:

powershell

iis

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?

like image 620
lara400 Avatar asked Jan 06 '23 21:01

lara400


1 Answers

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' 
like image 120
Mathias R. Jessen Avatar answered Jan 30 '23 20:01

Mathias R. Jessen