简体   繁体   English

response.redirect并抛入catch块

[英]response.redirect and throw in catch block

What will happen in the following scenario? 在以下场景中会发生什么? Will it throw work after response.redirect? 它会在response.redirect之后抛出工作吗?

Or do I need to use Response.Redirect in catch block of main method where it throws exception call stack.... 或者我需要在main方法的catch块中使用Response.Redirect,它会抛出异常调用堆栈....

try
{    
//code
}
catch(Exception ex)
{    
Response.Redirect("Error.aspx");
throw;    
}

Since you aren't supplying the parameter to indicate whether the current page should continue executing, it will automatically terminate the page by calling End(). 由于您未提供参数来指示当前页面是否应继续执行,因此它将通过调用End()自动终止页面。 Using the method with a single parameter is the same as calling the method with two parameters, with the second (endResponse) set to true . 使用带有单个参数的方法与使用两个参数调用方法相同,第二个(endResponse)设置为true Since End() results in an exception being thrown, it won't ever reach your throw statement. 由于End()导致抛出异常,因此它不会到达throw语句。

Reference: http://msdn.microsoft.com/en-us/library/a8wa7sdt.aspx 参考: http//msdn.microsoft.com/en-us/library/a8wa7sdt.aspx

When you use this method in a page handler to terminate a request for one page and start a new request for another page, set endResponse to true or call the Redirect method overload. 在页面处理程序中使用此方法终止对一个页面的请求并为另一个页面启动新请求时,请将endResponse设置为true或调用Redirect方法重载。 This method calls End for the original request, which throws a ThreadAbortException exception upon completion. 此方法为原始请求调用End,该请求在完成时抛出ThreadAbortException异常。

If you want the page to continue executing you need to use the signature with two parameters and set the endResponse parameter to false . 如果希望页面继续执行,则需要使用带有两个参数的签名,并将endResponse参数设置为false

If you call Response.Redirect (without the overload) then it should immediately stop execution and so the throw won't be raised. 如果你调用Response.Redirect(没有重载),那么它应该立即停止执行,因此不会引发throw。

However, if you use the overload and pass in false eg. 但是,如果你使用重载并传入false,例如。 Response.Redirect("Error.aspx", false) then it will continue execution of the page and then redirect. Response.Redirect("Error.aspx", false)然后它将继续执行页面然后重定向。

(At least, that is my understanding from the documentation) . (至少,这是我对文档的理解

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM