How to Avoid Response.End() “Thread was being aborted” Exception during the Excel file download

后端 未结 16 2249
感动是毒
感动是毒 2020-11-27 11:47

I tried to convert my dataset into excel and download that excel .I got my required excel file.But System.Threading.ThreadAbortException was raised every excel download. Ho

16条回答
  •  一整个雨季
    2020-11-27 12:25

    I recommend this solution :

    1. Don't use response.End();

    2. Declare this global var : bool isFileDownLoad;

    3. Just after your (response.Write(sw.ToString());) set ==> isFileDownLoad = true;

    4. Override your Render like :

      /// AEG : Very important to handle the thread aborted exception
      
      override protected void Render(HtmlTextWriter w)
      {
           if (!isFileDownLoad) base.Render(w);
      } 
      

提交回复
热议问题