Enable HTTP Compression on IIS for ASP.Net

If you enable HTTP compression on IIS, it does not enable compression for aspx files by default. You will have to edit the metabase or run the following commands and they will do it for you.

Important step: Make a backup of the file %windir%\System32\inetsrv\MetaBase.xml. If something goes wrong, then copy the original file back and restart the iis server.

Open a command prompt (cmd) and CD to the directory \Inetpub\AdminScripts.

Execute the following commands one at a time and verify that there are no errors.

net stop iisadmin

cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoDynamicCompression true

cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoStaticCompression true

cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcFileExtensions “htm” “html” “txt” “ppt” “xls” “xml” “pdf” “xslt” “doc” “xsl” “htc” “js” “css”

cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcFileExtensions “htm” “html” “txt” “ppt” “xls” “xml” “pdf” “xslt” “doc” “xsl” “htc” “js” “css”

cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions “asp” “dll” “exe” “aspx” “asmx” “ashx”

cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions “asp” “dll” “exe” “aspx” “asmx” “ashx”

net start w3svc

Done.

One of our web pages was about 3MB size and after compressing it, the page is only 170KB. That was about 30s improvement in page load time.