Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 3rd, 2003, 06:13 AM
Authorized User
 
Join Date: Jun 2003
Location: , , Yugoslavia.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thread was being aborted

Hi,
I have the folowing code

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click

Try
     Response.Redirect(Application("sRoot") & "Prva.aspx")

Catch ex As Exception
     Dim Greska As String
     Greska = ex.Message
     Greska = ex.ToString()
     Response.Redirect(Session("sRoot") & "GlobalError.aspx?ER=" & Greska)

End Try

A few days ago this code worked just fine and i could go to Prva.aspx,
but now i always get Exception (Thread was being aborted) and go to GlobalError.aspx.
Why?
Thanks, Alex
  #2 (permalink)  
Old November 3rd, 2003, 11:13 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Have you changed anything in the application in the last few days? There seems little reason for this to suddenly change unless you made some change with the configuration of the application.

One thing I can point out is that you usually should need to convert what you get from "Application()" into the appropriate data type before using it...

Response.Redirect(CType(Application("sRoot"), String) & "Prva.aspx")

Another suggestion is that if you want to reference a page based on your application root, you can do this:

Response.Redirect(ResolveURL("~/Prva.aspx"))

~ reference the application "home" directory, or the vitual directory. So no matter where this code is called from, the resulting value passed to the redirect will be something like "/MyWebApp/Prva.aspx".

Peter
  #3 (permalink)  
Old November 6th, 2003, 10:47 AM
Registered User
 
Join Date: Nov 2003
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to inancgumus Send a message via MSN to inancgumus
Default

The reason for the error is Response.Redirect method.

If you want to get rid of this exception, use Response.Redirect(url, false).

Instead of putting Response.Redirect into Try..Catch block. You may try this one:

Dim url As String

Try
    url = Application("sRoot") & "Prva.aspx"
Catch ex As Exception
    Dim Greska As String
    Greska = ex.Message
    Greska = ex.ToString()
    url = Session("sRoot") & "GlobalError.aspx?ER=" & Greska
End Try

Response.Redirect(url, False)

Sorry I didnt used to VB.Net, and some syntax error(s) may be occurred.

-----------------------------------------------

I'm going to write some about the situation; it may clarify your mind if you have some patience to read.

Your page is executing by a thread on which asp.net worker process contains. And on some line in your code, an instruction (Response.Redirect) wants to stop the execution because it must be stopped and asp.net framework must be notified about a redirection request.

Asp.net framework catches the Redirect method's exception, aborts the thread and use a new thread for execution of to be redirected page.

This occurs when you specify the second argument of Redirect method as True. Because this means to asp.net framework as 'Stop this page's execution ASAP and execute to be redirected page'.

...
Yesterday, I forgot to write down something about special exception class named ThreadAbortException.

You are getting this exception because Response.Redirect method internally calls Response.End method which raises this exception and the page processing terminates. Response.End raises this exception indirectly through calling Thread.Abort which raises this exception directly.

This exception is a special exception as I have said. The common language runtime has a special attention for this exception. When this exception occurs you can catch it in a catch block of a try...catch structure. And this exception will be raised again by the runtime at the end of the catch block. So, as you see, this is the reason why you are getting this exception even you were encapsulating Response.Redirect in a try...catch block.


Inanc Gumus

Software Architect

can be reached at inancgumus@hotmail.com
  #4 (permalink)  
Old November 9th, 2003, 01:51 PM
Authorized User
 
Join Date: Jun 2003
Location: , , Yugoslavia.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot
Alex
  #5 (permalink)  
Old December 11th, 2004, 01:55 PM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am calling a web service from asp.net (both written in VB.NET). When I
call the web service I get a ThreadAbortException (ex.message thread was
being aborted)

This problem does not occur however if I call the same web service from a
windows app. Now this web service and asp.net application is hosted offsite
and I dont have access to the machine.config file to lengthen the timeout
for the web session (let alone restart IIS).

Is there anything I can do to prevent this from happening???

Thanks in advance.

  #6 (permalink)  
Old March 22nd, 2006, 07:33 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Inanc Gumus,

Thanks so much for your post. I was getting the same error. Took the response.redirect out of the Try.. Catch block and no more exception.

Very much appreciated.

Thanks,
Richard

  #7 (permalink)  
Old August 22nd, 2006, 09:40 AM
Registered User
 
Join Date: Aug 2006
Location: , , Norway.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by gueladio
 I am calling a web service from asp.net (both written in VB.NET). When I
call the web service I get a ThreadAbortException (ex.message thread was
being aborted)
It is probably the ASP.NET server on the calling side that
terminates the application. If so, adding a line like this to your
local Web.config file should make the error go away:

   <httpRuntime executionTimeout="300"/>

Ulf Lunde
  #8 (permalink)  
Old October 9th, 2006, 07:13 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This may be solution for specific problems.

But when i send mail and then redirect to a page, it will skip the mail sending and goes to redirected page. But i want to send mail also.

How can i do it?

  #9 (permalink)  
Old October 9th, 2006, 10:10 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Are you calling SmtpMail.Send(mail) before you redirect?

--Stole this from a moderator

I will only tell you how to do it, not do it for you.††
Unless, of course, you want to hire me to do work for you.
  #10 (permalink)  
Old November 27th, 2006, 04:11 AM
Registered User
 
Join Date: Nov 2006
Location: , TX, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by inancgumus
 The reason for the error is Response.Redirect method.

If you want to get rid of this exception, use Response.Redirect(url, false).

Instead of putting Response.Redirect into Try..Catch block. You may try this one:

Dim url As String

Try
    url = Application("sRoot") & "Prva.aspx"
Catch ex As Exception
    Dim Greska As String
    Greska = ex.Message
    Greska = ex.ToString()
    url = Session("sRoot") & "GlobalError.aspx?ER=" & Greska
End Try

Response.Redirect(url, False)

Sorry I didnt used to VB.Net, and some syntax error(s) may be occurred.

-----------------------------------------------

I'm going to write some about the situation; it may clarify your mind if you have some patience to read.

Your page is executing by a thread on which asp.net worker process contains. And on some line in your code, an instruction (Response.Redirect) wants to stop the execution because it must be stopped and asp.net framework must be notified about a redirection request.

Asp.net framework catches the Redirect method's exception, aborts the thread and use a new thread for execution of to be redirected page.

This occurs when you specify the second argument of Redirect method as True. Because this means to asp.net framework as 'Stop this page's execution ASAP and execute to be redirected page'.

...
Yesterday, I forgot to write down something about special exception class named ThreadAbortException.

You are getting this exception because Response.Redirect method internally calls Response.End method which raises this exception and the page processing terminates. Response.End raises this exception indirectly through calling Thread.Abort which raises this exception directly.

This exception is a special exception as I have said. The common language runtime has a special attention for this exception. When this exception occurs you can catch it in a catch block of a try...catch structure. And this exception will be raised again by the runtime at the end of the catch block. So, as you see, this is the reason why you are getting this exception even you were encapsulating Response.Redirect in a try...catch block.


Inanc Gumus

Software Architect

can be reached at inancgumus@hotmail.com
Thank you for the useful insight. I had the same problem and solved it too. Thank you again. :) Keep up the good work.

 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread was being aborted error neptas ASP.NET 2.0 Professional 0 January 8th, 2008 08:00 AM
Thread was being aborted sohailmaroof ASP.NET 1.0 and 1.1 Basics 2 January 13th, 2007 02:25 AM
Message-thread is getting aborted. debjanib ASP.NET 1.0 and 1.1 Professional 1 July 27th, 2006 07:00 PM
Timeout and Thread was being aborted Vishal_7 ASP.NET 1.0 and 1.1 Basics 0 December 13th, 2004 02:08 PM



All times are GMT -4. The time now is 07:56 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.