【问题标题】:Error: Excepiton in System.Threading.ThreadAbortException: Thread was being aborted错误:System.Threading.ThreadAbortException 中的异常:线程被中止
【发布时间】:2014-07-11 06:18:30
【问题描述】:

下载模板时,我收到以下错误消息。

我尝试过代替 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();
}

提前谢谢..

【问题讨论】:

标签: c# asp.net multithreading


【解决方案1】:

在这里回答:- How to Avoid Response.End() "Thread was being aborted" Exception during the Excel file download

替换这个: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 exception "Thread was being aborted" causes method to exit

这是一个 ThreadAbortException;这是一个特殊的例外 在每个 catch 块结束时自动重新抛出,除非你 调用 Thread.ResetAbort()。

ASP .Net 方法,如 Response.End 或 Response.Redirect(除非你 pass false) 抛出此异常以结束当前的处理 页;您的 someFunctionCall() 可能正在调用其中之一 方法。

ASP .Net 自己处理这个异常并调用 ResetAbort 来 继续处理。

【讨论】:

  • 谢谢你的回答:)
猜你喜欢
  • 2014-10-17
  • 1970-01-01
  • 1970-01-01
  • 2015-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多