我在使用 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
发布评论