protected void Page_Load( object sender, EventArgs e)<br>{<br> try <br> {<br> if ( object .ReferenceEquals(Request[ "ID" ], "aaa" ))<br> {<br> Response.Redirect( "~/PageA.aspx" );<br> }<br> else if (Request[ "ID" ] == "bbb" )<br> {<br> Response.Redirect( "~/PageB.aspx" );<br> }<br> else <br> {<br> int i = int .Parse(Request[ "ID" ]);<br> object boxedI = i;<br> if ((i > 5) && (( long )boxedI == 10))<br> {<br> Response.Redirect( "~/Page10.aspx" );<br> }<br> Response.Redirect( "~/PageDafault.aspx" );<br> }<br> } <br> catch (Exception)<br> {<br> Response.Redirect( "~/Error.aspx" );<br> }<br>}<br> <br> * This source code was highlighted with Source Code Highlighter .
Response.Redirect
interrupts the flow of the page code execution, throwing a ThreadAbortException
for this. catch(Exception)
catches it, throwing it again in Response.Redirect
, but directing it to another page <<<catch(Exception)
: habrahabr.ru/blogs/net/77154/#comment_2246114 Despite the simplicity of this code, it does exactly what it needs: interrupts the execution of the code pages. Since a ThreadAbortException
exception is thrown at the end of the catch
, this will not lead to the execution of unnecessary code outside the try
block and in other page events. And the decision habrahabr.ru/blogs/net/77154/#comment_2245598 just leads to such an implementation, so I do not like <<<Source: https://habr.com/ru/post/77154/
All Articles