是否存在阻止Response.Redirect在try-catch块内工作的东西?

Vit*_*eis 9 .net c# try-catch visual-studio-2008

我得到了一些奇怪的错误,response.redirect()并且项目根本没有构建..当我删除了围绕代码块的try-catch块时,Response.Redirect()它正常工作..

只是想知道这是一个已知的问题还是什么......

M4N*_*M4N 23

如果我没记错的话,Response.Redirect()抛出异常来中止当前请求(ThreadAbortedException或类似的东西).所以你可能会抓住那个例外.

编辑:

知识库文章描述了此行为(也适用于Request.End()Server.Transfer()方法).

因为Response.Redirect()存在过载:

Response.Redirect(String url, bool endResponse)
Run Code Online (Sandbox Code Playgroud)

如果传递endResponse=false,则不抛出异常(但运行时将继续处理当前请求).

如果endResponse=true(或者如果使用了其他重载),则抛出异常并立即终止当前请求.