Response.redirect引发“线程被中止” [英] Response.redirect raises "Thread was being aborted"

查看:85
本文介绍了Response.redirect引发“线程被中止”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我需要从DB中删除对象时,我调用了一个VB.NET代码。在Page_load上,我检查它是否没有回发(以防止手动刷新),并且在删除对象后,我使用Response.redirect重定向到调用者页面。此时我的代码提出了

I've a VB.NET code called when I need to delete an object from DB. On Page_load I check if it's not post back (to prevent a manual refresh) and, after the deletion of the object I redirect to the caller page using Response.redirect. At this point my code raise an


异常:EXCEPTION OCCURS
File_delete.aspx.vb行号:34
错误消息:线程被
中止。

exception:EXCEPTION OCCURS In File_delete.aspx.vb Line Number: 34 Error Message: Thread was being aborted.

在事件查看器中我可以看到aspnet_wp.exe崩溃:

and, on Event Viewer I can see that aspnet_wp.exe crashes:


aspnet_wp.exe(PID:1532)意外停止

aspnet_wp.exe (PID: 1532) stopped unexpectedly.

有关详细信息,请参阅帮助和
支持中心,价格为
http:/ /go.microsoft.com/fwlink/events.asp

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

目前尚不清楚为什么这只发生在这里,因为我使用response.redirect也可以查看文件,而不仅仅是删除它。

It's not clear why this happens only here because I use the response.redirect also to view the file and not only to delete it.

推荐答案

默认情况下, Response.Redirect()中止当前线程。当然,这会抛出 ThreadAbortException 。可以通过将 false 传递给 Response.Redirect()来阻止它,它不会中止当前线程。

By default, Response.Redirect() aborts the current thread. Naturally, this throws a ThreadAbortException. It can be prevented by passing a false to Response.Redirect(), which won't abort the current thread.

但请注意这意味着什么。如果线程未中止,则 Response.Redirect()后面的代码将继续执行。相应地控制您的逻辑流程。 (这通常通过重定向后的 return 语句和其他流控制指令来完成。)

Be aware of what that means, however. If the thread is not aborted, the code following the Response.Redirect() will continue to execute. Control your logic flow accordingly. (This is often done with return statements and other flow control directives following a redirect.)

这篇关于Response.redirect引发“线程被中止”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆