Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I turn on DynamicCompression feature of IIS programmatically?

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.

like image 910
Thach Lockevn Avatar asked Mar 05 '10 04:03

Thach Lockevn


2 Answers

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)

like image 68
Jonas Lewin Avatar answered Sep 20 '22 19:09

Jonas Lewin


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.

like image 41
Nick Avatar answered Sep 20 '22 19:09

Nick