Can you set multiple file extensions to allowed for request filtering?
I am trying to add multiple file extensions to the allowed list for request filtering using the xWebConfigPropertyCollection resource but am stuck on exactly how to do it. I can add an individual extension, but can't figure out how to indicate multiples. Below adds one extension with the whole string. If I remove the ", .aspz" then it successfully adds the .aspx extension.
WebsitePath = 'MACHINE/WEBROOT/APPHOST' Filter = 'system.webServer/security/requestFiltering' CollectionName = 'fileExtensions' ItemName = 'add' ItemKeyName = 'fileExtension' ItemKeyValue = '.aspx, .aspz' ItemPropertyName = 'allowed' ItemPropertyValue = 'true' Ensure = 'Present'
Using the above configuration would result in this configuration <add fileExtension=".aspx, .aspz" />. This will mean that a file should be named like index.aspx, .aspz, which is not what you want to achieve. Instead you could loop over the extensions that you would like to allow and add all of them. That could look something like
Configuration Sample_xWebConfigPropertyCollection_Add
{
param
(
# Target nodes to apply the configuration.
[Parameter()]
[String[]]
$NodeName = 'localhost',
# File extensions to allow in request filtering configuration
[Parameter()]
[String[]]
$AllowedFileExtensions = @('.aspx', '.aspz')
)
# Import the modules that define custom resources
Import-DscResource -ModuleName xWebAdministration
Node $NodeName
{
foreach($extension in $AllowedFileExtensions)
{
xWebConfigPropertyCollection "$($NodeName) - Request Filtering allow fileextension $($extension)"
{
WebsitePath = 'MACHINE/WEBROOT/APPHOST'
Filter = 'system.webServer/security/requestFiltering'
CollectionName = 'fileExtensions'
ItemName = 'add'
ItemKeyName = 'fileExtension'
ItemKeyValue = $extension
ItemPropertyName = 'allowed'
ItemPropertyValue = 'true'
Ensure = 'Present'
}
}
}
}