ASP.NET Response.Redirect & Server.Transfer
Yes, another hurdle of the day that I encountered when I was testing the process flow of a registration website that I was in-charged with.
In classic ASP, there are 2 methods that could be used to transfer/redirect to another page:
ASP.NET is a totally new technology with an ASP.NET page ties with a background code written either in VB.NET or C#. Much like coding in Java Servlet, the background code is written in accordance to either VB.NET or C#, thus a lot of consideration to the process flow need to be dealt with.
Response.Redirect and Server.Transfer are 2 examples. According to some findings, if I tried to call a Response.Redirect within a try... catch... block, an Exception would be thrown and informed me that there is a thread being aborted. This happened because Response.Redirect will stop all the processes, and would call Response.End within itself to abort all processes. Thus the exception is thrown because Response.End being called to abort all processes. The solution to this would be to call the Response.Redirect outside of the try... catch... block, of which I would assume that the ideal time to call it is at the end of the code. I haven't found anything on Server.Transfer, of which I would assume that it is of the same problem.
In classic ASP, there are 2 methods that could be used to transfer/redirect to another page:
- Server.Transfer - What it does is that it will transfer all the state information like Session, Application, and all Request collections to another page, which the page will have the same Session ID as the previous page.
- Response.Redirect - Another method that would widely be used I believed. This method will stop all processes that are executed and then proceed to connect to a different URL. This method will not transfer the current state to the new URL.
ASP.NET is a totally new technology with an ASP.NET page ties with a background code written either in VB.NET or C#. Much like coding in Java Servlet, the background code is written in accordance to either VB.NET or C#, thus a lot of consideration to the process flow need to be dealt with.
Response.Redirect and Server.Transfer are 2 examples. According to some findings, if I tried to call a Response.Redirect within a try... catch... block, an Exception would be thrown and informed me that there is a thread being aborted. This happened because Response.Redirect will stop all the processes, and would call Response.End within itself to abort all processes. Thus the exception is thrown because Response.End being called to abort all processes. The solution to this would be to call the Response.Redirect outside of the try... catch... block, of which I would assume that the ideal time to call it is at the end of the code. I haven't found anything on Server.Transfer, of which I would assume that it is of the same problem.
Comments