For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > July 2005 > ThreadAbort on redirect?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author ThreadAbort on redirect?
javatopia

2005-07-31, 5:18 pm

Hello,

I have a simple redirect on a login page:

Login_Click()
{
// ... do the login verification
try {
Response.Redirect("index.aspx");
}
catch(Exception ex) {
// Get ThreadAbortException here!
}
}

When I catch the ThreadAbortException, the redirect fails to work, and I am
left back on the login page. Subsequent attempts also result in
ThreadAbortException.

I am wondering if this would happen when the aspnet_wp process recycles the
application instance? Is there anything that can be done to recover from the
ThreadAbortException being raised?? Maybe the Server.Transfer() would be
more reliable in ASP.NET??

Thanks

-- Jake

Brock Allen

2005-07-31, 5:18 pm

The ThreadAbortException is a little trick that ASP.NET uses to do the Response.Redirect
(actually, it's how it does Response.End()). This does work, as long as in
your catch blocks you're not affecting what the Redirect was doing. Also,
if you're running in the debugger and you have it set to break on all exceptions
then you won't see what you're expecting. From VS.NET, to run you page use
Ctrl-F5, not F5.

-Brock
DevelopMentor
http://staff.develop.com/ballen



> Hello,
>
> I have a simple redirect on a login page:
>
> Login_Click()
> {
> // ... do the login verification
> try {
> Response.Redirect("index.aspx");
> }
> catch(Exception ex) {
> // Get ThreadAbortException here!
> }
> }
> When I catch the ThreadAbortException, the redirect fails to work, and
> I am left back on the login page. Subsequent attempts also result in
> ThreadAbortException.
>
> I am wondering if this would happen when the aspnet_wp process
> recycles the application instance? Is there anything that can be done
> to recover from the ThreadAbortException being raised?? Maybe the
> Server.Transfer() would be more reliable in ASP.NET??
>
> Thanks
>




Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com