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

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

问题描述

当我需要从数据库中删除一个对象时,我调用了一个 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

异常:异常发生在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天全站免登陆