正在中止线程 的问题解决

错误描述:正在中止线程
如果使用 Response.EndResponse.Redirect 或 Server.Transfer 方法,将出现 ThreadAbortException 异常。您可以使用 try-catch 语句捕获此异常。

原因

Response.End 方法终止页的执行,并将此执行切换到应用程序的事件管线中的 Application_EndRequest 事件。不执行 Response.End 后面的代码行。

此问题出现在 Response.Redirect 和 Server.Transfer 方法中,因为这两种方法均在内部调用 Response.End。

要解决此问题,请使用下列方法之一:

1、对于 Response.End,调用 HttpContext.Current.ApplicationInstance.CompleteRequest 方法而不是 Response.End 以跳过 Application_EndRequest 事件的代码执行 

2、对于 Response.Redirect,请使用重载 Response.Redirect(String url, bool endResponse),该重载对 endResponse 参数传递 false 以取消对 Response.End 的内部调用。例如: Response.Redirect ("nextpage.aspx", false); 

 


posted @ 2011-01-05 14:53  TSPWATER'S HOME  阅读(353)  评论(0编辑  收藏  举报