Response.Redirect and Response.End

I discovered once myself automatically writing redirects like this:


Response.Redirect("otherpage.aspx");
Response.End();

 

NB! This blog is moved to gunnarpeipman.com

Click here to go to article

2 Comments

  • This will never work....

    Response.Redirect("otherpage.aspx");
    Response.End();

    Response.End(); is never going to get called because you have already redirected the response to another page. Create this statement, set a breakpoint on the Response.End(); and watch it never get called.

    The second approach you mentioned using the ResponseEndEnum will work fine, but your argument is moot as your first approach doesn't work.

  • First approach works because redirection takes place. Just Response.End is not run. It is there like "Game Over" when you get killed in action game. It is not part of game, there is no action anymore and it is purely informative. It sais to reader that there happens nothing after redirect - it is the point where response is over.

Comments have been disabled for this content.