I was trying to enable downloading of a file from an ASP .NET page, using TransmitFile method, and using content-disposition response header. Everything was right when testing on localhost, but when deploying to IIS on a Windows Server 2003 box, even that the file could be successfully downloaded, the file size was displayed as “Not Known” during the download process.
First, I was incorretcly trying to resolve the problem by applying a content-length header to the response, but this was NOT the correct solution (it didn’t work, but it’s also not logically correct), as the actual (not known) content-length is actually overwritten by ASP .NET itself (this is by the ASP .NET design, and therefore expected behavior).
The resolution was to disable application file compression on IIS, on the Windows Server 2003 machine:
- In IIS Manager, expand the local computer, right-click the Web Sites folder, and then click Properties.
- Click the Service tab, and in the HTTP compression section, unselect the Compress application files check box to disable dynamic compression.
Update: Note that if you do disable dynamic compression, depending on what other roles your Windows Server machine has, some client-server communication may not work or may need to be reconfigured (for example, Outlook client connection to an Exchange Server installed on the same machine). Be extra careful and do test all the applications that rely on server connections when you apply the change. Or, you may want to apply the change (disable application files compression) only for a specific Web site instead.