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