Can someone explain this error to me?: System.Threading.ThreadAbortException: Thread was being aborted. I understand what it is saying, just not why it would be raised. It is happening inside my try-catch block. I am trying to redirect to another page inside
of the try, which I imagine is what is throwing the exception. What is the better way to do this? Here is my code for reference:
private void btnSubmit_Click(object sender, System.EventArgs e)
{
try
{
bool alreadyExists = true;
bool alreadyInUse = true; //false;
bool emailExists = true;
// HIDE THE ERROR MESSAGE
lblError.Visible = false;
// CHECK TO SEE IF THE USER ALREADY EXISTS
log = new abc.Components.Login();
alreadyExists = log.CheckExistingUser(tbLastName.Text, tbFirstName.Text, tbEmail.Text, tbUserName.Text);
// CHECK TO SEE IF THE USERNAME IS VALID
log = new abc.Components.Login();
alreadyInUse = log.CheckUserName(tbUserName.Text);
// CHECK TO SEE IF THE E-MAIL IS ALREADY IN USE
log = new abc.Components.Login();
emailExists = log.CheckEmail(tbEmail.Text);
if(alreadyExists==false)
{
if(alreadyInUse==false)
{
if(emailExists==false)
{
// SUBMIT USER DATA
reg = new abc.Components.Register();
int userID;
// SUBMIT USER INFO AND CONTACT INFO
userID = reg.AddUser(tbLastName.Text, tbFirstName.Text, tbEmail.Text, tbUserName.Text,
tbPassword.Text ,tbAddress1.Text, tbAddress2.Text, tbCity.Text, ddlState.Items[ddlState.SelectedIndex].Value,
tbZip.Text, ddlCountry.Items[ddlCountry.SelectedIndex].Value, tbPhone.Text);
// SET A USERID SESSION VARIABLE
//Session["userID"] = userID;
// SUBMIT USER STATION INFO
reg = new abc.Components.Register();
bool stationSuccess;
stationSuccess = reg.AddUserStation(userID, (string)Session["BranchID"], (string)Session["Base"],
(string)Session["yearFrom"], (string)Session["yearTo"]);
if(userID > 0 && stationSuccess)
{
try
{
// SEND E-MAIL TO USER
// SETUP EMAIL
string subject = "Your Login!";
string body = "" + tbFirstName.Text + ",
" +
"Our developers are currently working on the user profile section. At this time, " +
"our login area is incomplete. You will be notified when the section is complete so that " +
"you can login and personalize your account.
" +
"Thank you,
" +
"The Webmaster
";
sm = new abc.Components.SendMail();
sm.SendMessage(tbEmail.Text, "webmaster", subject, body);
}
catch (Exception ex)
{
// WRITE EXCEPTION TO EXCEPTION TABLE
// e-mail didn't send for new user
}
// GO TO THE DUTY STATION THEY JUST SELECTED
Response.Redirect("http://localhost/abc/DutyStations/DutyStation.aspx");
}
else
{
Response.Redirect("http://localhost/abc/ErrorPages/Error.aspx?status=0");
}
}
else
{
// EMAIL ALREADY EXISTS
lblError.Text = "That e-mail address is already in the database.";
//. . . you need to log in.
lblError.Visible = true;
}
}
else
{
// "uname already taken, please try another one"
lblError.Text = "That user name already exists, please select another one.";
lblError.Visible = true;
}
}
else
{
// "Appears already exist. Want uname and password mailed?"
lblError.Text = "It looks like you have previously registered with abc, please login.";
lblError.Visible = true;
}
}
catch (Exception ex)
{
Response.Redirect("http://localhost/abc/ErrorPages/Error.aspx?status=2");
}
}
// GO TO THE DUTY STATION THEY JUST SELECTED
Response.Redirect("http://localhost/abc/DutyStations/DutyStation.aspx");
So if anyone can offer any suggestions, I would greatly appreciate it. It used to work fine, but I decided to go back and
actually add error handling. . . :) Thanks.
HI Usually I used to get this error if I had used Server.Transfer() or Server.Execute() in a Try Catch block. So I changed over to Response.Redirect(). Then it worked fine. But it is peculiar that you are getting even with Response.Redirect(). Why are you giving
the entire url. Did you try using only the virtual path. HSSR
It was my understanding that virtual paths are a security hole and that IIS 6 will not allow them. I was basically just trying to code for the future. I can try using a virtual path when I get home though to see if that changes things.
Hi, I think now you have got the solution of threading problem.In my previous project i used to get this problem whenever i used Response.redirect inside try catch bock,but after 3-4 months now again i am trying the same thing the behaviour is that it catches
the exception from the Response.redirect statement inside try block then it goes to catch part and instead of writing the exception message it redirects to the url i gave in try block,please suggest me why the behaviour is so. I tried this block of code in
page load event. Try Response.redirect ("WebForm1.aspx") Catch exc as exception Response.write(exc.tostring) End Try
Using System.Threading; Try to catch the ThreadAbortException in the final catch block where the exception is occuring catch( ThreadAbortException e) { // your code here Thread.RestAbort(); }
I have noticed that it throws the error in the Try Catch Blocks but not Try Finally Blocks. Don't know if this helps any one, but there it is. This is VB.Net, ASP.Net 1.1, IIS 5.1 for those keeping score.
From what I understand this is expected behavior when doing a response.redirect (as you are doing). See http://groups.google.com/groups?q=ThreadAbortException+response.redirect&hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&selm=2HRbuc4dDHA.2000%40cpmsftngxa06.phx.gbl&rnum=1
and http://support.microsoft.com/default.aspx?scid=KB;EN-US;312629 For more information. Response.Redirect(url, false) worked for me. Dennis Webb
http://support.microsoft.com/default.aspx?scid=KB;EN-US;312629 For more information. Response.Redirect(url, false) worked for me. Dennis Webb
It worked for me too... now the interesting part of it all, my code was working perfectly and for no reason, it started throwing the exceptions.... mmmhhhh....
Jose
Jose
Please remember to click "Mark as Answer" on the post that helps you, and to click "Mark as Not Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
craigt-from-...
Participant
908 Points
226 Posts
System.Threading.ThreadAbortException: Thread was being aborted.
Jun 12, 2003 12:44 PM|LINK
private void btnSubmit_Click(object sender, System.EventArgs e) { try { bool alreadyExists = true; bool alreadyInUse = true; //false; bool emailExists = true; // HIDE THE ERROR MESSAGE lblError.Visible = false; // CHECK TO SEE IF THE USER ALREADY EXISTS log = new abc.Components.Login(); alreadyExists = log.CheckExistingUser(tbLastName.Text, tbFirstName.Text, tbEmail.Text, tbUserName.Text); // CHECK TO SEE IF THE USERNAME IS VALID log = new abc.Components.Login(); alreadyInUse = log.CheckUserName(tbUserName.Text); // CHECK TO SEE IF THE E-MAIL IS ALREADY IN USE log = new abc.Components.Login(); emailExists = log.CheckEmail(tbEmail.Text); if(alreadyExists==false) { if(alreadyInUse==false) { if(emailExists==false) { // SUBMIT USER DATA reg = new abc.Components.Register(); int userID; // SUBMIT USER INFO AND CONTACT INFO userID = reg.AddUser(tbLastName.Text, tbFirstName.Text, tbEmail.Text, tbUserName.Text, tbPassword.Text ,tbAddress1.Text, tbAddress2.Text, tbCity.Text, ddlState.Items[ddlState.SelectedIndex].Value, tbZip.Text, ddlCountry.Items[ddlCountry.SelectedIndex].Value, tbPhone.Text); // SET A USERID SESSION VARIABLE //Session["userID"] = userID; // SUBMIT USER STATION INFO reg = new abc.Components.Register(); bool stationSuccess; stationSuccess = reg.AddUserStation(userID, (string)Session["BranchID"], (string)Session["Base"], (string)Session["yearFrom"], (string)Session["yearTo"]); if(userID > 0 && stationSuccess) { try { // SEND E-MAIL TO USER // SETUP EMAIL string subject = "Your Login!"; string body = "" + tbFirstName.Text + ",
The exception is being caught here:" + "Welcome!
" + "Your username and password are:
" + "**********************
" + "Username: " + tbUserName.Text + "
" + "Password: " + tbPassword.Text + "
" + "**********************
" + "Our developers are currently working on the user profile section. At this time, " + "our login area is incomplete. You will be notified when the section is complete so that " + "you can login and personalize your account. " + "Thank you,
" + "The Webmaster
"; sm = new abc.Components.SendMail(); sm.SendMessage(tbEmail.Text, "webmaster", subject, body); } catch (Exception ex) { // WRITE EXCEPTION TO EXCEPTION TABLE // e-mail didn't send for new user } // GO TO THE DUTY STATION THEY JUST SELECTED Response.Redirect("http://localhost/abc/DutyStations/DutyStation.aspx"); } else { Response.Redirect("http://localhost/abc/ErrorPages/Error.aspx?status=0"); } } else { // EMAIL ALREADY EXISTS lblError.Text = "That e-mail address is already in the database."; //. . . you need to log in. lblError.Visible = true; } } else { // "uname already taken, please try another one" lblError.Text = "That user name already exists, please select another one."; lblError.Visible = true; } } else { // "Appears already exist. Want uname and password mailed?" lblError.Text = "It looks like you have previously registered with abc, please login."; lblError.Visible = true; } } catch (Exception ex) { Response.Redirect("http://localhost/abc/ErrorPages/Error.aspx?status=2"); } }
catch (Exception ex) { Response.Redirect("http://localhost/abc/ErrorPages/Error.aspx?status=2"); }. . . and the line that is throwing the error is:// GO TO THE DUTY STATION THEY JUST SELECTED Response.Redirect("http://localhost/abc/DutyStations/DutyStation.aspx");So if anyone can offer any suggestions, I would greatly appreciate it. It used to work fine, but I decided to go back and actually add error handling. . . :) Thanks.Hssr
Member
5 Points
1 Post
Re: System.Threading.ThreadAbortException: Thread was being aborted.
Jun 12, 2003 03:12 PM|LINK
craigt-from-...
Participant
908 Points
226 Posts
Re: System.Threading.ThreadAbortException: Thread was being aborted.
Jun 12, 2003 04:08 PM|LINK
ruchisethi
Member
30 Points
6 Posts
Re: System.Threading.ThreadAbortException: Thread was being aborted.
Jun 25, 2003 04:56 AM|LINK
azamsharp
All-Star
24614 Points
4612 Posts
Re: System.Threading.ThreadAbortException: Thread was being aborted.
Jun 27, 2003 12:46 AM|LINK
HighOnCoding
dsellers
Member
195 Points
39 Posts
Re: System.Threading.ThreadAbortException: Thread was being aborted.
Dec 05, 2003 02:18 AM|LINK
dsellers
Member
195 Points
39 Posts
Re: System.Threading.ThreadAbortException: Thread was being aborted.
Dec 05, 2003 03:03 AM|LINK
denniswebb
Member
15 Points
3 Posts
Re: System.Threading.ThreadAbortException: Thread was being aborted.
Dec 05, 2003 02:28 PM|LINK
JSantaMaria
Participant
751 Points
147 Posts
Re: System.Threading.ThreadAbortException: Thread was being aborted.
Jun 29, 2006 04:10 PM|LINK
It worked for me too... now the interesting part of it all, my code was working perfectly and for no reason, it started throwing the exceptions.... mmmhhhh....
Jose
Please remember to click "Mark as Answer" on the post that helps you, and to click "Mark as Not Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
e_screw
All-Star
19530 Points
3894 Posts
Re: System.Threading.ThreadAbortException: Thread was being aborted.
Jun 29, 2006 05:32 PM|LINK
Have a look at my another post regarding ThreadAbortException
Thanks
Electronic Screw
Website||Blog||Dub@i.net