Meeting the needs of your business from a distance

Streaming files to client in ASP.NET and Compression

by Mark Shiffer 9/4/2008 2:50:00 PM

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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Issues | Programming

Related posts

Comments

September 5. 2008 09:11

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 us

September 5. 2008 09:29

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 us

Add comment


(Will show your Gravatar icon)  

  Country flag





Live preview

November 21. 2008 06:53

About the author

Name of author Mark Shiffer
CEO & CIO of MS Consulting

E-mail me Send mail

Calendar

<<  November 2008  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar

Pages

    Recent posts

    Recent comments

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2008

    Sign in

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