How can I turn on DynamicCompression feature of IIS programmatically?
Asked Answered
T

5

9

I'm making an installer program for my web application. My web application uses CSS and JS heavily, so I want to enable both Static and Dynamic HttpCompression for IIS7/7.5.

It needs 2 steps:

  1. I can modified the web.config, put <httpcompression> tag, it's ok.
  2. DynamicContentCompression must be turned on in Windows Feature to make httpCompression work.

Static HttpCompression is enable by default in IIS7 and IIS7.5, but Dynamic HttpCompression is not enable by default (although it's available). I can do manually by turn on: Start/ControlPanel/ProgramsAndFeatures/TurnWindowsFeatures on or Off/IIS/WWW Service/Performance features/Dynamic Content Compression, but How can I programmatically turn it on that Windows Feature? I can use PowerShell, C# in my installer.

Any idea how I might be able to do this? Thanks.

Tiddly answered 5/3, 2010 at 4:54 Comment(0)
H
11

This is the way I would have done it:

dism /online /enable-feature /featurename:IIS-HttpCompressionDynamic

dism allows you to check the return code of command, allowing you to verify that it worked (or was already installed)

Hale answered 3/6, 2014 at 13:10 Comment(0)
H
7

These PowerShell commands will add add the Dynamic Compression feature.

Import-Module ServerManager
Add-WindowsFeature Web-Server, Web-Dyn-Compression

Don't forget to Run As Administrator or have administrator rights.

Herbal answered 6/2, 2015 at 1:35 Comment(1)
Please improve your answerCaputto
O
1

You can turn this on using the appcmd tool. From a command line:

C:\windows\system32\inetsrv\appcmd set config /section:urlCompression /doDynamicCompression:True

Or if you want to execute it from within a PowerShell script:

& $env:windir\system32\inetsrv\appcmd set config -section:urlCompression /doDynamicCompression:true

You're going to need administrative privileges to do either.

Ostrogoth answered 5/3, 2010 at 5:22 Comment(1)
Thanks Greg, but that addcmd is not Turn on the Windows Feature I need.Tiddly
A
1

Disclaimer: this is totally unproven and untested ....

Greg's answer above is nearly right, but that only unlocks the installed feature. By default, when that feature is installed, it's locked down ... all the way down at the machine level.

The rational is because dynamic compression can really frak with the servers CPU. So in a hosting environment, this could kill things. Even with your own dedicated server, it could also kill things badly. So the safe route is to lock it by default and only if u know what you're doing, then go and unlock it.

So .. having a quick google search, i came to this page.

Notice how this technet article has a commandline thingy to install all the required packages for a sample static IIS server. I know your question is not for a static IIS server ... but it does higlight the commands possible.

So i'm guessing ... maybe this? ::

Start /w pkgmgr /iu:IIS-HttpCompressionDynamic

?? maybe :)

here's another article with more options...

Abell answered 19/3, 2010 at 23:19 Comment(0)
C
0
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionDynamic
Cubical answered 4/11, 2020 at 19:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.