gpt4 book ai didi

c# - 错误 : Excepiton in System. Threading.ThreadAbortException:线程被中止

转载 作者:太空宇宙 更新时间:2023-11-03 20:04:29 24 4
gpt4 key购买 nike

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

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

提前致谢..

最佳答案

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

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.

并在这里回答:- ASP.NET exception "Thread was being aborted" causes method to exit

This is a ThreadAbortException; it's a special exception that is automatically rethrown at the end of every catch block, unless you call Thread.ResetAbort().

ASP .Net methods like Response.End or Response.Redirect (unless you pass false) throw this exception to end processing of the current page; your someFunctionCall() is probably calling one of those methods.

ASP .Net itself handles this exception and calls ResetAbort to continue processing.

关于c# - 错误 : Excepiton in System. Threading.ThreadAbortException:线程被中止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24691232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com