开发者

response.redirect and throw in catch block

What will h开发者_开发知识库appen in the following scenario? Will it throw work after response.redirect?

Or do I need to use Response.Redirect in catch block of main method where it throws exception call stack....

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(). Using the method with a single parameter is the same as calling the method with two parameters, with the second (endResponse) set to true. Since End() results in an exception being thrown, it won't ever reach your throw statement.

Reference: 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. This method calls End for the original request, which throws a ThreadAbortException exception upon completion.

If you want the page to continue executing you need to use the signature with two parameters and set the endResponse parameter to false.


If you call Response.Redirect (without the overload) then it should immediately stop execution and so the throw won't be raised.

However, if you use the overload and pass in false eg. Response.Redirect("Error.aspx", false) then it will continue execution of the page and then redirect.

(At least, that is my understanding from the documentation).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜