Response.Redirect generates Exception

G

Guest

Hi,
I have an <asp:Button> control on a page. When it is clicked, I run a db
stored procedure and then I want to go to the next page by executing a
Response.Redirect("NextPage.aspx?id=" + myID).
The Response.Redirect always generates an Exception "Thread was being
aborted."
Is there a way to execute Response.Redirect without generating this
exception? (I cannot use Server.Transfer is this particular case).
Or can I achieve the same functionality (execute a stored proc and go to
another page) in a different way?

Thanks.
 
J

John Rivers

in fact

response.redirect(url, false)

is nearly always recommended
as how does the method that calls response.redirect(url, true)
have any way of knowing there is nothing else important going
to happen next?

in classic asp it was common to emulate this

by using a RedirectURL variable as follows:

Dim RedirectURL
Start() 'calls main page processing
If Len(RedirectURL) > 0 Then
Response.Redirect RedirectURL
End If

this made sure that important code wasn't skipped
for instance you would wrap all your asp pages
in a common library function to enable uniform
code processing of say logging utilities and custom
session handling code and all sorts of good things
 
G

Guest

Hi,

The exception is thrown because thread is being terminated, which is the
most logical way to end the response. Always use try - catch statement when
calling End, Redirect and Transfer methods. John - again - this newsgroup is
not about classic ASP :)

AND STOP MAKING STUPID POSTS AND ANSWERS :)
 
J

John Rivers

I must protest.

There is nothing stupid about my answer.

My reference to Classic ASP was to highlight the fact that
a shortcoming of cASP was a Response.Redirect method that
stopped code dead, and that this has been fixed in ASP.NET
with the Response.Redirect(url, false) overload.

If you don't agree with my comment please feel free to write
to microsoft and ask them to remove that feature.

If you can't see the danger in allowing threads to be suddenly
terminated, instead of code running to a natural end and then
redirecting, I recommend you ask someone else, whose
opinion you do value, to explain it to you.

Until then I look forward to watching one of your connections
with an open transaction getting returned to the pool or
a serviced component exiting before disposal and watching
your panicky face as you realise ...

Please see:

http://en.wikipedia.org/wiki/Nincompoop

for further guidance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top