Currently I have an issue on an ASP.NET Web Form application, where some people are not able to get the fully downloaded file being requested.
The file does download fully sometimes, but other times it stays hanging after a certain amount of bytes, and eventually the browser seems to suggest a network error. Again I would like to emphasis sometimes it’s fine, other times the download is just stuck and not responding. I have tried putting a try/catch but nothing is being returned.
I cannot replicate this on a test web server, it only happens on production which makes this issue more difficult to find.
It seems nothing passed the flush, statement is being executed when this happens. If it doesn’t occur all is normal.
public void DownloadFile(byte[] fileImage, string fileName )
{
if (fileImage == null) return;
string fileExt = fileName.Substring(fileName.LastIndexOf('.') + 1);
string disposition = string.Format("attachment;filename="{0}"", fileName);
Response.Clear();
Response.Buffer = true;
Response.ContentType = GetContentType(fileExt);
Response.ContentEncoding = System.Text.Encoding.Default;
Response.AddHeader("content-disposition", disposition);
Response.BinaryWrite(fileImage);
Response.Flush();
Response.End();
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
So I found out the issue was caused by a Load balancer and not the code. The manner in which the load balancer was handling SSL seemed to be the key thing that caused this. For now the solution was to offload SSL Handling to the Web Server.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0