有什么是prevents的Response.Redirect工作try-catch块里面? [英] Is there something that prevents Response.Redirect to work inside try-catch block?

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

问题描述

我得到了一些奇怪的错误与的Response.Redirect(),该项目并没有建立在所有。当我删除了的的try-catch 被周围的code其中的Response.Redirect()是它的block块正常工作。

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()存在过载:

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.

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

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