This code streams large files to our users:
// Open the file.
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Ope
That exception means that the client downloading the file broke the connection before the file had finished downloading. i.e. The client navigated to another page, or just closed the browser.
I might try moving the if (Response.IsClientConnected)
line after your iStream.Read
. Even if you did that, I think there still might be a chance to receive this error if the connection is broken while the OutputStream.Write
method is still working.
There are a few different possible causes of this. I can think of three:
One is filling the buffer with close to 2GB of data, but this shouldn't be the case here, since you are flushing regularly.
Another is indeed that described in the answer you previously accepted. It's very hard to reproduce, so I wouldn't assume it was necessarily wrong.
Another possible case, and the one I would bet on, is that the executionTimeout is exceeded, which would cause a ThreadAbortException at first, but this could in turn cause the failure of Flush() which would turn into the exception noted
I am posting this answer because it might be help others and save some important time.
In my case Response.Buffer = true
in download method (on very first statement) solved the issue.
Thanks
Increase executionTimeout in httpRuntime element of web.config.
If user is downloading large file on slow connection, request will eventually timeout.