![](/img/trans.png)
[英]System.Threading.ThreadAbortException: Thread was being aborted - which Thread?
[英]Error: Excepiton in System.Threading.ThreadAbortException: Thread was being aborted
在下載模板時,我收到以下錯誤消息。
我嘗試代替Response.Flush(); 與Response.End();。 但是得到同樣的錯誤。
Error: Excepiton in Download:System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
任何避免上述異常的想法
碼
private void DownloadFile(string filePath, string downloadFileName)
{
Response.ContentType = "application/ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=" + downloadFileName);
Response.TransmitFile(filePath);
// Response.Flush();
Response.End();
}
提前致謝..
如這里回答:- 如何避免Response.End()“線程被中止” Excel文件下載期間出現異常
替換為:
HttpContext.Current.Response.End();
有了這個 :
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**
執行鏈並直接執行EndRequest事件。
並在這里回答: -ASP.NET異常“線程被中止”導致方法退出
這是一個ThreadAbortException; 這是一個特殊的異常,除非您調用Thread.ResetAbort(),否則它將在每個catch塊的末尾自動重新拋出。
諸如Response.End或Response.Redirect之類的ASP .Net方法(除非您傳遞false)將引發此異常以結束當前頁面的處理; 您的someFunctionCall()可能正在調用這些方法之一。
ASP .Net本身會處理此異常,並調用ResetAbort繼續處理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.