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:
  1. 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.
  2. 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.
The above methods can be executed from the ASP file with ease. Since ASP.NET has both methods provided to us, I would assume that it would behave the same. Yet, I was wrong.

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

Popular posts from this blog

Yahoo! Messenger voice call & video call disabled, why?

Sport's Injuries - Treatment for bruises

Web Development: Disable, Validate, & Enable Buttons