473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

"Thread was being aborted" exception on redirect - VERY weird!!

Hello,

I have a page that is supposed to do some checking, and if OK, set a
session variable before redirecting to another page. The following code
is a simplified version, I have hard-coded the basket ID and removed a
load of extra checking...

public partial class GoToCheckout : Page {
public void Page_Load(Object o, EventArgs e) {
try {
Session["basketid"] = "178";
//x.Text = "redirecting to PreCheckout.aspx";
Response.Redirect("PreCheckout.aspx");
} catch (Exception ex) {
Response.Redirect("/?msg=" + ex.Message);
//x.Text = "exception - " + ex.Message;
}
}
}

When this page is called, it throws a "Thread was being aborted"
exception when it hits the line...

Response.Redirect("PreCheckout.aspx");

The catch block picks it up and redirects to the home page, putting the
exception message in the querystring. I did this because if I comment
out the redirect in the catch and instead use the (commented out) x.Text
bit (x is a literal, put on the otherwise empty .aspx file for
debugging), then the redirect works fine!!

If I comment out the redirect in the try block and uncomment the x.Text
line there, then the page displays the message "redirecting to
PreCheckout.aspx" exactly as expected.

So, it seems there's some weird problem with the redirect, but I can't
work it out. Nor can I work out why changing the behaviour of the code
in the catch block changes whether the exception is raised or not.

This code has been working fine for a few months now. I have recently
been changing pages to use master pages and themes, which is when I
noticed the problem. However, if I now change this page back to not use
a master or theme, the problem is still there. I am totally baffled, and
would appreciate any help you can offer. TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Dec 6 '05 #1
5 2000
There is a second, optional parameter to the Response.Redirect call. It
is a boolean value that indicates whether or not to continue processing
the current page. Set it to false, and you should not get the errors
anymore.

Example:

Response.Redirect("PreCheckout.aspx", false);

JP

Alan Silver wrote:
Hello,

I have a page that is supposed to do some checking, and if OK, set a
session variable before redirecting to another page. The following code
is a simplified version, I have hard-coded the basket ID and removed a
load of extra checking...

public partial class GoToCheckout : Page {
public void Page_Load(Object o, EventArgs e) {
try {
Session["basketid"] = "178";
//x.Text = "redirecting to PreCheckout.aspx";
Response.Redirect("PreCheckout.aspx");
} catch (Exception ex) {
Response.Redirect("/?msg=" + ex.Message);
//x.Text = "exception - " + ex.Message;
}
}
}

When this page is called, it throws a "Thread was being aborted"
exception when it hits the line...

Response.Redirect("PreCheckout.aspx");

The catch block picks it up and redirects to the home page, putting the
exception message in the querystring. I did this because if I comment
out the redirect in the catch and instead use the (commented out) x.Text
bit (x is a literal, put on the otherwise empty .aspx file for
debugging), then the redirect works fine!!

If I comment out the redirect in the try block and uncomment the x.Text
line there, then the page displays the message "redirecting to
PreCheckout.aspx" exactly as expected.

So, it seems there's some weird problem with the redirect, but I can't
work it out. Nor can I work out why changing the behaviour of the code
in the catch block changes whether the exception is raised or not.

This code has been working fine for a few months now. I have recently
been changing pages to use master pages and themes, which is when I
noticed the problem. However, if I now change this page back to not use
a master or theme, the problem is still there. I am totally baffled, and
would appreciate any help you can offer. TIA

--
Alan Silver
(anything added below this line is nothing to do with me)


Dec 6 '05 #2
I think what's happening is that your first Redirect is ending the page
execution, and thus the request/response. Try passing in "false" as a
second param to Redirect to see if that helps; it tells the redirect not to
end the thread on that call. Another option, since you're within your
application, is to use Server.Transfer instead, as it's more efficient
within the app.
Dec 6 '05 #3
>There is a second, optional parameter to the Response.Redirect call. It
is a boolean value that indicates whether or not to continue processing
the current page. Set it to false, and you should not get the errors
anymore.


Thanks for the reply. Shortly after posting (ain't that always the
way!!), I found http://tinyurl.com/cj3qp where someone points out that
using Response.Redirect inside a try/catch blocks throws this exception.
I moved it outside the block and the problem went away.

I may change it back and try it with this second parameter though as the
code was neater before.

Thanks for the reply.

--
Alan Silver
(anything added below this line is nothing to do with me)
Dec 6 '05 #4
>I think what's happening is that your first Redirect is ending the page
execution, and thus the request/response. Try passing in "false" as a
second param to Redirect to see if that helps; it tells the redirect not to
end the thread on that call. Another option, since you're within your
application, is to use Server.Transfer instead, as it's more efficient
within the app.


Thanks. See my reply to Joey ;-)

--
Alan Silver
(anything added below this line is nothing to do with me)
Dec 6 '05 #5
>I may change it back and try it with this second parameter though as
the code was neater before.


I did, and it was ;-)

Thanks again to both of you

--
Alan Silver
(anything added below this line is nothing to do with me)
Dec 6 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

82
by: nobody | last post by:
Howdy, Mike! mikecoxlinux@yahoo.com (Mike Cox) wrote in message news:<3d6111f1.0402271647.c20aea3@posting.google.com>... > I'm a C++ programmer, and have to use lisp because I want to use >...
4
by: 6tc1 | last post by:
Hi all, I have just finished debugging a windows application and have solved the problem - however, I want to be sure that I understand the problem before I move on. Before I detail the problem,...
5
by: Peter Oliphant | last post by:
I'm drawing graphics using the Graphics object one can grab in a Form's Paint event. But I'm getting a weird thing happening... These graphic shapes flicker (even if unchanged). UNLESS- I created...
6
by: Sam | last post by:
I have some issues with HTTP Headers and I was hoping for some pointers or references to good articles. Here is the problem. I have 6 .aspx pages, each page contains a common .ascx. This ascx...
0
by: Johanna | last post by:
Hello, Thread was being aborted exception is thrown by my asp.net application. I hope someone could help me with this error that I get in windows 2003 server. This error has not occured with...
3
by: Johanna | last post by:
Hello, Thread was being aborted exception is thrown by IIS for my asp.net application on win2003 server. This error has not yet occured with the same asp.net application on windows 2000...
3
by: Prasad Dannani | last post by:
Hi, I was created a web service which will execute some functions and will do some database activities related to our project When i execute this method directly from browser using webservice...
2
by: Jeff | last post by:
I have some code that enables users to download the contents of a DataGrid as an Excel file. The following code snippet is the relevant part. It works just fine - meaning specifically that the...
4
by: R.A.M. | last post by:
Hello, Could you help me plase? I have an ASP.NET page with "Search" button; when button is clicked Search_Click is called; here's the code: protected void Search_Click(object sender, EventArgs...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.