ASP.NET 引发了异常: mscorlib.dll 中的“System.Threading.ThreadAbortException”(“正在中止线程。”) 错误解决办法

 

画面中出现了System.Threading.ThreadAbortException错误

 

 

在Hello.aspx源代码如下 

 

Response.Clear()
Response.ContentType = "text/plain"
Response.Write("Hello world")
Response.End()

  

使用Response.End()会抛出错误System.Threading.ThreadAbortException,本来该语句是用来阻止显示ASPX原来的内容,但是会引发错误.

解决方法有三种

 

1.使用ashx代替aspx, 因为ashx没有自带的HTML内容,所以不需要使Response.End()语句,代码改为以下形式

Response.Clear()
Response.ContentType = "text/plain"
Response.Write("Hello world")

 

2.使用Me.Visible=False就可以不显示ASPX自带的HTML内容,代码如下.

Me.Visible = False
Response.Clear()
Response.ContentType = "text/plain"
Response.Write(sText)
ApplicationInstance.CompleteRequest() '使 ASP.NET 跳过 HTTP 执行管线链中的所有事件和筛选并直接执行 

 

 

第3种方法参考 https://www.bbsmax.com/A/Ae5Rg1DNdQ/,就是用SuppressContent控制,设置为True

Response.Clear();
Response.ContentType = "application/json";
Response.Write(ResponseJsonStr);
Response.Flush(); 
Response.SuppressContent = true; ApplicationInstance.CompleteRequest(); return;

 

posted @ 2020-03-10 01:24  Firstwing  阅读(1710)  评论(0)    收藏  举报