Wednesday, February 2, 2011

Response.Close()

Interesting article on Dynamic Compression and Response.Close().

http://forums.iis.net/t/1152058.aspx

I found myself researching Response.Close() recently due to an issue with streaming attachments back to the browser.

The following code had always worked in the past, but for one particular environment we found that not all of the data was being written back in the BinaryWrite.

Response.Buffer = False
Response.ClearHeaders()
Response.ContentType = File.FileType
Response.AddHeader("Content-Disposition", "attachment; filename=" & File.FileName)
Response.BinaryWrite(File.FileData)
Response.Close()
Response.End()


Removing the Response.Close() fixed the problem. It was likely an issue with the load balancer in that environment, which wasn't present in the other environments.

The absence of the Response.Close() works in all situations, so I've decided to standardize on not using Response.Close() unless there are obvious reasons otherwise.

0 comments: