ASP.NET:Response.Redirect(...)之后的代码会怎样? [英] ASP.NET: What happens to code after Response.Redirect(...)?
问题描述
Response.Redirect()是否导致当前正在运行的方法中止?还是Response.Redirect()之后的代码也执行?
Does Response.Redirect() cause the currently running method to abort? Or does code after Response.Redirect() execute also?
(也就是说,是否有必要在Response.Redirect之后返回/退出Sub?)
(That is, is it necessary to return/Exit Sub after a Response.Redirect?)
推荐答案
这可能不是一个完整的答案,但根据我所见...
This may not be a complete answer, but from what I've seen...
Response.Redirect确实会通过引发System.Threading.ThreadAbortException导致代码停止执行.
Response.Redirect does, actually cause the code to stop executing by throwing a System.Threading.ThreadAbortException.
您可以通过在Global.Asax中设置全局错误处理并测试Response.Redirect来亲自查看.
You can see this for yourself by setting up global error handling in the Global.Asax and testing a Response.Redirect.
编辑
这是指向支持我的答案的文档的链接:
and here is a link to the documentation that supports my answer:
重定向呼叫End会引发一个出现ThreadAbortException异常完成.
Redirect calls End which raises a ThreadAbortException exception upon completion.
HttpResponse.Redirect方法(字符串,布尔值)(系统.Web)
这篇关于ASP.NET:Response.Redirect(...)之后的代码会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!