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

后端 未结 16 2276
感动是毒
感动是毒 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:06

    I researched online and saw that the Response.End() always throws an exception.

    Replace this: HttpContext.Current.Response.End();

    With this:

    HttpContext.Current.Response.Flush(); // Sends all currently buffered output to the client.
    HttpContext.Current.Response.SuppressContent = true;  // Gets or sets a value indicating whether to send HTTP content to the client.
    HttpContext.Current.ApplicationInstance.CompleteRequest(); // Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event.
    

提交回复
热议问题