我已经看到了几个关于这个问题的问题,但我没有找到适合我的问题的答案。最初我在函数中编写 json 后使用以下代码
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.SuppressContent = True;
HttpContext.Current.ApplicationInstance.CompleteRequest();
变得Server cannot append header after HTTP headers have been sent
异常。
所以我将代码更改为
try {
HttpContext.Current.Response.Write(Data);
HttpContext.Current.Response.End();
} catch (System.Threading.ThreadAbortException exc) {
try {
//Sends the response buffer
HttpContext.Current.Response.Flush();
// Prevents any other content from being sent to the browser
HttpContext.Current.Response.SuppressContent = true;
//Directs the thread to finish, bypassing additional processing
HttpContext.Current.ApplicationInstance.CompleteRequest();
} catch (Exception ex) {
//Log Exception
}
}
所有这些代码都在函数中(比如说)writeData()
,它由一个名为CallWriteData
. 现在该异常已在函数中成功处理,但在父函数中WriteData()
抛出异常。Thread was being aborted
CallWriteData
老实说,这不是我项目中的主要问题,但如果我能解决这个烦人的问题,那就太好了。CallWriteData
此外,并非每次都出现此异常 (有时已成功处理)。