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

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

    This is not issue but this is by design. The root cause is described in Microsoft Support Page.

    The Response.End method ends the page execution and shifts the execution to the Application_EndRequest event in the application's event pipeline. The line of code that follows Response.End is not executed.

    The provided Solution is:

    For Response.End, call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution to the Application_EndRequest event

    Here is the link: https://support.microsoft.com/en-us/help/312629/prb-threadabortexception-occurs-if-you-use-response-end--response-redi

提交回复
热议问题