ASP.NET"正在中止线程"错误原及解决方法
最近做的系统中老出现的一些问题不太明白,在使用 Response.End、Response.Redirect 或 Server.Transfer 时出现 ThreadAbortException ,本来系统是没有问题的,在保存数据时也可以正常,本来使用try-catch 语句是用来捕获一异常情况的,但系统正常,老捕获到下面的东西
##[操作记录]:2010-02-23 9:25:12 System.Threading.ThreadAbortException: 正在中止线程。
症状
如果使用 Response.End、Response.Redirect 或 Server.Transfer 方法,将出现 ThreadAbortException 异常。您可以使用 try-catch 语句捕获此异常。
原因
<!-- Inject Script Filtered -->
Response.End 方法终止页的执行,并将此执行切换到应用程序的事件管线中的 Application_EndRequest 事件。不执行 Response.End 后面的代码行。
此问题出现在 Response.Redirect 和 Server.Transfer 方法中,因为这两种方法均在内部调用 Response.End。
解决方案
要解决此问题,请使用下列方法之一:
对于 Response.End,调用 HttpContext.Current.ApplicationInstance.CompleteRequest 方法而不是 Response.End 以跳过 Application_EndRequest 事件的代码执行。
对于 Response.Redirect,请使用重载 Response.Redirect(String url, bool endResponse),该重载对 endResponse 参数传递 false 以取消对 Response.End 的内部调用。例如:
Response.Redirect ("nextpage.aspx", false);
如果使用此替代方法,将执行 Response.Redirect 后面的代码。
对于 Server.Transfer,请改用 Server.Execute 方法。
相关文档:
1.什么是cookie?
cookie 是一小段文本信息,伴随用户请求,在web服务器和浏览器之间传递。用户每次访问站点的时候,
web应用程序都可以读取cookie包含的信息。
假设在用户请求您的网站的某个页面时,您的应用程序不仅是返回请求的页面。同时也返回一个包含日期
和时间的cookie。用户的浏览器在获得页面的同时也获得了 ......
IIS自身是不能处理像ASPX扩展名这样的页面,只能直接请求像HTML这样的静态文件,之所以能处理ASPX这样扩展名的页面,是因为IIS有一个ISAPI过滤器,它是一个COM组件。ASP.NET服务在注册到IIS的时候,就会添加一个Win32的扩展动态库aspnet_isapi.dll。并将扩展可以处理的页面扩展名(如ASPX)注册到IIS里面。扩展启动后,就根 ......
The following is a simple checklist you can use when building web
applications. Much of this still applies to other technologies and can
easily be extended. I try not to get too specific on technology or
methodology, but it is definitely leaning toward ASP.NET.
If you
......
char[] constant = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', ......