有什么可以阻止 Response.Redirect 在 try-catch 块内工作吗? [英] Is there something that prevents Response.Redirect to work inside try-catch block?

查看:10
本文介绍了有什么可以阻止 Response.Redirect 在 try-catch 块内工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I got some weird error with response.redirect() and the project wasn't building at all.. when I removed the try-catch block that was surrounding the block of code where Response.Redirect() was in it worked normally..

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

Just want to know if this is a known issue or something...

推荐答案

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

If I remember correctly, Response.Redirect() throws an exception to abort the current request (ThreadAbortedException or something like that). So you might be catching that exception.

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

This KB article describes this behavior (also for the Request.End() and Server.Transfer() methods).

对于 Response.Redirect() 存在一个重载:

For Response.Redirect() there exists an overload:

Response.Redirect(String url, bool endResponse)

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

If you pass endResponse=false, then the exception is not thrown (but the runtime will continue processing the current request).

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

If endResponse=true (or if the other overload is used), the exception is thrown and the current request will immediately be terminated.

这篇关于有什么可以阻止 Response.Redirect 在 try-catch 块内工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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