2017-04-23 89 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