IIS6 Compression Breaks DotNetZip

Jul 8, 2010 at 4:33 PM

I am attempting to configure IIS Compression on IIS6, and after I update the MetaBase.xml with the compression settings I can no longer get the zip files with work.  The zip file will still download from the site, but when you try and open the file it says the zip file is invalid.  If I remove the compression settings it works fine.  Any thoughts?

Zip code sample

Using zip As New ZipFile()
         'removed code section here#################### 

            'Note: zip files and send to client
            Response.Clear()
            Response.ClearHeaders()
            Response.BufferOutput = False
            'Dim ReadmeText As String = String.Format("M. J. Harris, Inc. Disclaimer" & Environment.NewLine & Environment.NewLine & _
            '                                         "The information in this file should not be used without the expressed " & _
            '                                         "written conscent of the document's owner.")
            Dim archiveName As String = String.Format("MJHI-Planroom-{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"))
            Response.ContentType = "application/zip"
            Response.AddHeader("content-disposition", "filename=" + archiveName)

            zip.AddFile(Server.MapPath("Disclaimer and Intellectual Property Statement.txt"), "")

            'zip.AddEntry("Readme.txt", ReadmeText, Encoding.Default)
            ' filesToInclude is a string[] or List<String>
            zip.AddFiles(PlansToInclude, "01. Plans")
            zip.AddFiles(SpecsToInclude, "02. Specifications")
            zip.AddFiles(AddendaToInclude, "03. Addenda")
            zip.Encryption = EncryptionAlgorithm.None
            zip.Save(Response.OutputStream)
        End Using
        Response.Close()

Default MetaBase.xml elements

<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"
 >
</IIsCompressionSchemes>

Modified MetaBase.xml elements - compress enabled

<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/deflate"
  HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
  HcCreateFlags="0"
  HcDoDynamicCompression="TRUE"
  HcDoOnDemandCompression="TRUE"
  HcDoStaticCompression="TRUE"
  HcDynamicCompressionLevel="9"
  HcFileExtensions="htm
   html
   txt
   css
   js
   xml
   deploy"
  HcOnDemandCompLevel="9"
  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="9"
  HcFileExtensions="htm
   html
   txt
   css
   js
   xml
   deploy"
  HcOnDemandCompLevel="9"
  HcPriority="1"
  HcScriptFileExtensions="asp
   dll
   exe
   aspx
   asmx"
 >
</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="1048576000"
  HcMaxQueueLength="1000"
  HcMinFileSizeForComp="1"
  HcNoCompressionForHttp10="TRUE"
  HcNoCompressionForProxies="TRUE"
  HcNoCompressionForRange="FALSE"
  HcSendCacheHeaders="FALSE"
 >
</IIsCompressionSchemes>

Related Articles:
http://weblogs.asp.net/owscott/archive/2004/01/12/57916.aspx
http://www.kavinda.net/2007/02/17/how-to-enable-http-compression-iis6.html

Coordinator
Jul 12, 2010 at 9:04 PM
Try maybe using Response.End() in place of Response.Close() In theory, there's no reason why you couldn't use IIS6 compression with DotNetZip.
Jul 12, 2010 at 9:54 PM

Cheeso, thanks for the suggestion.  Unfortunately this did not correct the issue.

Jul 12, 2010 at 10:14 PM
Edited Jul 12, 2010 at 10:15 PM

It appears that the issue was with my Response.ContentType once I implemented the compression in IIS6. Making the following change seems to have cleared things up: Response.ContentType = "application/x-gzip-compressed"