2013-03-31 31 views
-1

我使用下面的代碼來下載文件,但我面對Response.End總是導致Exception。這是我的應用程序行爲的成本?如果是的話,如何才能獲得另一種下載文件的方式。我試圖用Thread.ResetAbort()來處理異常,但這樣的結果不需要額外的數據將被添加到文件使用Response.End()的代價()

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); 
      } 
+0

你有什麼異常? –

+0

線程異常終止! –

+2

請參閱:http://stackoverflow.com/questions/1087777/is-response-end-considered-harmful –

回答