使用 DSC 配置 IIS

Configure IIS with DSC

如何使用 xWebAdministration DSC 模块配置 static\dynamic http 压缩?据我了解,DSC 不提供直接配置这些方法的方法,但也许 xWebConfigKeyValue 可以做到这一点?如果是这样,你有一些例子吗?

还有这个:

New-WebHandler -Name "svc-ISAPI-4.0_64bit" -Path "*.svc" -Verb 'GET,POST' -Modules IsapiModule
New-WebHandler -Name "svc-Integrated-4.0" -Path "*.svc" -Verb 'GET,POST' -Modules 'System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

使用 xIisHandler?但是如何?

解决方案:

$mimeTypesDynamic = @(
    @{mimeType='text/*'; enabled='True'},
    @{mimeType='message/*'; enabled='True'},
    @{mimeType='application/x-javascript'; enabled='True'},
    @{mimeType='application/json'; enabled='True'},
    @{mimeType='application/json; charset=utf-8'; enabled='True'},
    @{mimeType='application/xml" enabled'; enabled='True'},
    @{mimeType='application/xml; charset=utf-8'; enabled='True'},
    @{mimeType='*/*'; enabled='false'}
)

$mimeTypesStatic = @(
    @{mimeType='text/*'; enabled='True'},
    @{mimeType='message/*'; enabled='True'},
    @{mimeType='application/x-javascript'; enabled='True'},
    @{mimeType='application/atom+xml'; enabled='True'},
    @{mimeType='application/xaml+xml'; enabled='True'},
    @{mimeType='*/*'; enabled='false'}
)

...


Script configureMime {
    SetScript = {
        Remove-WebHandler -Name "svc-Integrated-4.0" -WarningAction SilentlyContinue
        Remove-WebHandler -Name "svc-ISAPI-4.0_64bit"
        Clear-WebConfiguration -filter "/system.webServer/httpCompression/dynamicTypes" -pspath IIS: -WarningAction SilentlyContinue
        Clear-WebConfiguration -filter "/system.webServer/httpCompression/staticTypes" -pspath IIS: -WarningAction SilentlyContinue
        foreach ($mimeD in $using:mimeTypesDynamic) {
            Add-WebConfiguration "/system.webServer/httpCompression/dynamicTypes" -pspath IIS: -value $mimeD
            New-Item c: -ItemType Directory -ea 0
        }
        foreach ($mimeS in $using:mimeTypesStatic) {
            Add-WebConfiguration "/system.webServer/httpCompression/staticTypes" -pspath IIS: -value $mimeS
        }
        New-WebHandler -Name "svc-ISAPI-4.0_64bit" -Path "*.svc" -Verb 'GET,POST' -Modules IsapiModule
        New-WebHandler -Name "svc-Integrated-4.0" -Path "*.svc" -Verb 'GET,POST' -Modules 'System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
    }
    TestScript = { 
        $types = Get-WebConfigurationProperty -Filter "/system.webServer/httpCompression" -name dynamicTypes
        $types.Collection.Length -eq 8
    }
    GetScript = { return @{ 'Result' = "Mimi Configuration" } }   
}

据我从 xWebAdministration 的源代码中可以看出,xWebConfigKeyValue 似乎只支持 appsettings-values,而 xIISHandler 只接受预定义的处理程序。因此,您将不得不使用脚本资源或创建自己的资源来配置这些设置(或寻找一些第三方模块)。

为了帮助您入门,以下是在全局级别修改动态和静态压缩的示例:

#Enable dynamicCompression global (remember to install dynamic compression feature first)
Set-WebConfigurationProperty -Filter "/system.webServer/urlCompression" -PSPath IIS:\ -Name doDynamicCompression -Value "true"

#Enable staticCompression global
Set-WebConfigurationProperty -Filter "/system.webServer/urlCompression" -PSPath IIS:\ -Name doStaticCompression -Value "true"