views:

158

answers:

2

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.

A: 

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.

Greg Shackles
Thanks Greg, but that addcmd is not `Turn on the Windows Feature` I need.
LockeVN
A: 

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...

Pure.Krome