473,231 Members | 1,861 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,231 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 1990
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.