Thursday, January 04, 2007

Response.Redirect and ThreadAbortException

Response.Redirect..
That's the method that made me anxious and nervous and pissed off..

When you have a web page(main.aspx) and you want to go to another(second.aspx), you most often use
Response.Redirect("second.aspx");
at the code of main.aspx.

Until one day your project doesn't work and you get a ThreadAbortException.
You cannot imagine the reason, unless you spend some time on the net(or read it here in advance;) ).

The problem is that Response.Redirect(url), calls the Response.End internally, which terminates the thread of the main page from the call stack. That results in this exception.

The best practice, is to use the Response.Redirect(url, false) instead of Response.Redirect(url). False, is a boolean that defines that the thread of the main page should continue to be executed and not terminated.

That's all.. Just one more parameter :)
more info here and here.

3 comments:

Unknown said...

RTFM :)

vpapanik said...

RTFS (S for Stavros) :D

Stavros Amanatidis said...

none of you has faced the problem I guess :)