首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用DSC配置IIS

用DSC配置IIS
EN

Stack Overflow用户
提问于 2017-04-23 13:13:24
回答 1查看 1.9K关注 0票数 0

如何使用xWebAdministration DSC模块配置静态\动态http压缩?据我所知,DSC并没有提供一种直接的方式来配置这些,但是也许xWebConfigKeyValue可以这样做呢?如果是的话,你有一些例子吗?

此外,这也是:

代码语言:javascript
复制
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?但是怎么做呢?

解决方案:

代码语言:javascript
复制
$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" } }   
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-23 19:22:05

据我所见,从xWebAdministration的源代码中可以看出,xWebConfigKeyValue只支持应用程序设置-值,xIISHandler只接受预定义的处理程序。因此,您必须使用脚本资源或创建自己的资源来配置这些设置(或找到一些第三方模块)。

为了让您开始,下面是在全局级别上修改动态和静态压缩的示例:

代码语言:javascript
复制
#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"
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43571624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档