Users of our application download the application at least once every two seconds during the day.
Previous scenario:
We used Response.End () to disconnect from the client after the user loads the attachment. Since we had performance issues, we started logging exceptions, and one of the most recurring was the interruption exception. Since we get attachment to the web service, we need to do some cleanup, and we cleared the try-catch-finally block. After some research, I realized that any code after Response.End () will not be executed, even if it is at the end of the block. Is it correct?
Current scenario:
I read the thread in the stack overflow about Response.End (), which is harmful, and should be used only when it is really necessary, so I decided to use HttpContext ... CompleteRequest (). This code performs the cleanup, but the html that is displayed is added to the downloaded application. I tried to override the Render and RaisePostBackEvent suggested in the same article, but the problem still persists. Any idea on how to solve this problem would be helpful.
The code:
HttpContext.Current.Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); Response.AddHeader("Content-Length", fileContent.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(fileContent); Response.Flush();
source share