2017-04-23 52 views
-1

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

而且也是这样:

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:\1 -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" } } 
} 
+0

xIISHandler只接受处理的预定义列表(https://github.com/PowerShell/xWebAdministration/斑点的/ dev/DSCResources/MSFT_xIIsHandler/MSFT_xIisHandler.psm1)。您可以使用脚本资源。 –

+0

好的,你知道压缩吗? @FrodeF。 – 4c74356b41

+0

您可能需要xwebconfigkeyvalue(或使用脚本资源)。搜索PowerShell示例,找到所需的路径和值,将其设置为 –

回答

1

据我可以从源代码参见xWebAdministration它看起来像xWebConfigKeyValue仅支持的AppSettings值和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" 
+0

我认为这是别的?我的意思是,urlCompression!= httpCompression?我正在寻找这样做:'appcmd.exe设置config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='text/*',enabled='True']“/ commit:apphost'。显然,我不能将它设置为true,需要传递实际数据'mimiType ='text/*'(也许'enabled ='True''也是?)。另外,我想我可以用'Get-WebConfigurationProperty'来测试存在吗? – 4c74356b41

+0

您从未指定过您要配置的内容....这是您启用/禁用http压缩的方式。 httpcompression-部分用于定义启用后的行为。仅供参考,我已经投票结束这个问题,因为它不清楚。请阅读StackOverflow的帮助并更新问题。 –

+0

很好,谢谢你的讲解,但正如你可能想到的,我在这里有7k的评级,而且我对规则很满意,但是我可以问这个问题,因为我从来没有和IIS一起工作过。 – 4c74356b41