Meeting the needs of your business from a distance

Streaming files to client in ASP.NET and Compression

by Mark Shiffer 4. September 2008 21:50

I recently ran across an issue that took me a while to finally work through. I have a web page that generates a PDF document and streams it down to the browser for viewing. Pretty simple, common functionality. I've done it before without issue. I threw the page together tested it locally in VS and it worked fine. I then copied the page into an existing website (Team System Web Access) and tested from there. What was returned was the pdf document appended with a number of extra bytes that was actually a copy of another area within the document. After a great deal of searching, coding the solution in many different ways, changing IIS7 settings, I finally came to the resolution. In the web.config file for TSWA, it had a compression module that was being used. After I removed that module, the file then came down correctly.

I guess the larger question here is how to get it to work with that compression module still in play. I doubt I will even try that as the module is specific to TFWA and there is not much information available on how it is performing its compression. For reference the line I removed was: <add name="CompressionModule" type="Microsoft.TeamFoundation.WebAccess.CompressionModule" />

Tags: ,

Issues | Programming

Comments

9/5/2008 4:11:28 PM #

EJ

Obviously that sort of thing should be completely transparent to code producing output.  So, the only thing that comes to mind is maybe your code is working with output buffers incorrectly like, as an example, using data returned from MemoryStream.GetBuffer() instead of MemoryStream.ToArray().  The former returning the entire internal buffer of data, which can include extra garbage (in the form of old/previously outputted data) at the end.

So I guess I'd just check over any buffer usage you're dealing with.

EJ United States | Reply

9/5/2008 4:29:48 PM #

Mark Shiffer

Good thought, however, the code on the server side is using stream.ToArray() and then as part of testing I was saving that byte[] to a file on the server before writing the same array to the Response. That file was correct. I also tried flipping the BufferOutput flag on the Response, but there was no difference. My original thought was that I was setting the Content-Length in correctly or shoving the bytes into the response incorrectly. I tried several different ways of writing the bytes to the response all of which worked locally but not on the server.

Mark Shiffer United States | Reply

Add comment


(Will show your Gravatar icon)

  Country flag


  • Comment
  • Preview
Loading



Copyright © 2001-2012 MS Consulting, Inc. All Rights Reserved.