Wednesday, August 29, 2007

IIS MetaEdit

Found a tool for editing the IIS 5.0 MetaBase.

How to enable HTTP Compression in IIS 6.0 for ASP.NET

Here is my simple guide to setting it up.

Step 1: Configuring Web Service Extensions in IIS Manager

  1. Open Internet Information Services (IIS) Manager
  2. Right-click the Web Service Extensions
  3. Click on Add a new Web Service extension...
  4. Enter Extension Name (recommend Http Compression)
  5. Click Add...
  6. Select C:\WINDOWS\system32\inetsrv\gzip.dll (alter path to your windows install directory as appropriate)
  7. Check the Set extension status to Allowed
  8. Click Ok
  9. In Web Service Extensions you should now see Http Compression and its status of Allowed
Step 2: Configuring the IIS Metabase xml file

The metabase.xml file is located at c:\windows\system32\inetsrv\MetaBase.xml and contains the compression configuration.

  1. Stop IIS
  2. Run below commands from the command prompt OR edit the metabase.xml to match the below modified version of the configuration.
  3. Start IIS

The original configuration without changes looks like this:

<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/deflate"
HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
HcCreateFlags="0"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="FALSE"
HcDynamicCompressionLevel="0"
HcFileExtensions="htm
html
txt"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="asp
dll
exe"
>
</IIsCompressionScheme>
<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/gzip"
HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
HcCreateFlags="1"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="TRUE"
HcDynamicCompressionLevel="0"
HcFileExtensions="htm
html
txt"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="asp
dll
exe"
>
</IIsCompressionScheme>
<IIsCompressionSchemes Location ="/LM/W3SVC/Filters/Compression/Parameters"
HcCacheControlHeader="max-age=86400"
HcCompressionBufferSize="8192"
HcCompressionDirectory="%windir%\IIS Temporary Compressed Files"
HcDoDiskSpaceLimiting="FALSE"
HcDoDynamicCompression="FALSE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="FALSE"
HcExpiresHeader="Wed, 01 Jan 1997 12:00:00 GMT"
HcFilesDeletedPerDiskFree="256"
HcIoBufferSize="8192"
HcMaxDiskSpaceUsage="100000000"
HcMaxQueueLength="1000"
HcMinFileSizeForComp="1"
HcNoCompressionForHttp10="TRUE"
HcNoCompressionForProxies="TRUE"
HcNoCompressionForRange="FALSE"
HcSendCacheHeaders="FALSE"
>


The modified configuration to correctly configure compression looks like this:

<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/deflate"
HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
HcCreateFlags="0"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="TRUE"
HcDynamicCompressionLevel="10"
HcFileExtensions="htm
html
txt
ppt
xls
xml
pdf
xslt
doc
xsl
htc
js
css"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="asp
dll
exe
aspx
asmx"
>
</IIsCompressionScheme>
<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/gzip"
HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
HcCreateFlags="1"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="TRUE"
HcDynamicCompressionLevel="10"
HcFileExtensions="htm
html
txt
ppt
xls
xml
pdf
xslt
doc
xsl
htc
js
css"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="asp
dll
exe
aspx
asmx
ashx"
>
</IIsCompressionScheme>
<IIsCompressionSchemes Location ="/LM/W3SVC/Filters/Compression/Parameters"
HcCacheControlHeader="max-age=86400"
HcCompressionBufferSize="8192"
HcCompressionDirectory="%windir%\IIS Temporary Compressed Files"
HcDoDiskSpaceLimiting="FALSE"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="TRUE"
HcExpiresHeader="Wed, 01 Jan 1997 12:00:00 GMT"
HcFilesDeletedPerDiskFree="256"
HcIoBufferSize="8192"
HcMaxDiskSpaceUsage="100000000"
HcMaxQueueLength="1000"
HcMinFileSizeForComp="1"
HcNoCompressionForHttp10="FALSE"
HcNoCompressionForProxies="FALSE"
HcNoCompressionForRange="FALSE"
HcSendCacheHeaders="FALSE"
>

Here is a couple of commands you can run to automatically update your compression configuration to get the above settings:

cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcFileExtensions "htm" "html" "txt" "ppt" "xls" "xml" "pdf" "xslt" "doc" "xsl" "htc" "js" "css"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp" "dll" "exe" "aspx" "asmx"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcDoDynamicCompression "TRUE"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcDoOnDemandCompression "TRUE"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcDoStaticCompression "TRUE"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcDynamicCompressionLevel "10"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcFileExtensions "htm" "html" "txt" "ppt" "xls" "xml" "pdf" "xslt" "doc" "xsl" "htc" "js" "css"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "dll" "exe" "aspx" "asmx" "ashx"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcDoDynamicCompression "TRUE"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcDoOnDemandCompression "TRUE"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcDoStaticCompression "TRUE"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcDynamicCompressionLevel "10"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcDoDynamicCompression "TRUE"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcDoOnDemandCompression "TRUE"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcDoStaticCompression "TRUE"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcNoCompressionForHttp10 "FALSE"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcNoCompressionForProxies "FALSE"
cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcNoCompressionForRange "FALSE"


Note: I tried adding the .AXD extension for Web Resources and it works util I tried using AJAX.ASP.NET. The ScriptManager in AJAX library does its own Gzip compression of its .AXD files. This custom behavior causes the response to be double Gzip encoded resulting in a corrupted response. So far, I found no way to disable the ScriptManager from performing the compression of its own the resources. So sad. Seems like the ASP.NET team forgot to discuss with the IIS team what it was capable of doing.

Step 3: Check to make sure it works

I recommend using YSlow (FireFox Plug-in) and FireFox to check to see it your getting the compression for your web site and its components (css, js, etc.) You should now see that your page and its associations are now compressed. I did notice that small files (<3k) didn't seem to get compressed.

ASP.NET and Ajax

I found a third-party component (Ajaxium) which makes the entire page use Ajax for all post-backs.

ASP.NET and Gzip Compression

Found an interesting article discussing how to accomplish compression on JavaScript resources.

As it turns out, IIS 5.0 might be able to handle gzip compression natively for Aspx, which I found reading the ASP.NET: 10 tips for Writing High Performance Web Sites. For configuring IIS 6.0 I found this article and this other one helpful.

For some performance statistics on http compression check this out.

Saturday, August 25, 2007

Visual Studio 2005: Web Deployment Projects

I've got to read this sometime.

Massively GRANT permissions

The below little SQL Server 2005 script will generate GRANT T-Sql statements for all objects in the database. Fun stuff. There has to be a way to do this through the administration tools quickly... But, until I find it.

SELECT
CASE
WHEN type IN ('U','TF','FN','IF') THEN 'GRANT ALL ON ' + name + ' TO PUBLIC'
WHEN type IN ('P') THEN 'GRANT EXEC ON ' + name + ' TO PUBLIC'
END sql
FROM sys.all_objects WHERE schema_id = [change me] AND type IN ('U','TF','IF','FN','P')

Need to make sure you change the 'schema_id' to the schema_id of the database you want to run the script on. Oh, and the types are probably not complete, so BEWARE. All you have to do is then take the output and run it. Fun, fun and no hard type etc.

The script would also be handy for generating other broad categories of T-Sql for any objects in the database. Nothing though any DBA couldn't do in 5 minutes.

DISCLAIMER: Blah, blah, blah this is for development purposes only and you should do better than just granting ALL access to the PUBLIC. Done.
There was an error in this gadget