有什么可以阻止 Response.Redirect 在 try

编程入门 行业动态 更新时间:2024-10-28 20:31:48
本文介绍了有什么可以阻止 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

本文发布于:2023-06-08 23:39:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/591058.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   Response   Redirect

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!