-1

I'm using the following code to to download files, but I'm face that Response.End always causes Exception. Is This cost for my application behavior? if yes how can get an alternative way to download files. I tried to use Thread.ResetAbort() to handle the exception but this result unwanted additional data to be added to the file

try
            {
                   DownloadFiles();                       
                   Response.End();                   
            }
            catch (ThreadAbortException)
            {
               // Thread.ResetAbort();
            }
            catch (GSException ex)
            {
                Response.ClearHeaders();
                hdnResult.Value = ex.Message;
                // ClientScript.RegisterStartupScript(this.Page.GetType(), "checkDownloadError", "window.parent.checkDownloadError('" + ex.Message + "');", true);
            }
            catch (Exception)
            {
                Response.ClearHeaders();
                hdnResult.Value = "Oops! Something unexpected happened. Please try again later";
                //ClientScript.RegisterStartupScript(this.Page.GetType(), "checkDownloadError", "window.parent.checkDownloadError('Oops! Something unexpected happened. Please try again later');", true);
            }   
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Raed Alsaleh
  • 1,581
  • 9
  • 27
  • 50

1 Answers1

0

If you don't want to pay the exception throw cost that comes with Response.End you could use the Application.CompleteRequest method instead.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928