Response.Redirect within Try Catch

Hi,

I am using asp.net 2.0 and I have a page where I need to use the Try-Catch-Finally structure.

Within the Try statement I have various commands and then at the end of it I have a Response.Redirect("....") to take the user to another page.

Within my catch statement I also have a Response.Redirect("../errorPage.htm") which will take you to the error page if any exceptions occur.

However, I have tested the page and I know there are no exceptions happening but the user is still getting redirected to the error page.  Is there anyway to make this not happen?

I am using Smart Navigation, if this helps build a picture.

Could anyone please help with this?  It would be very much appreachiated.

0
thedodgecriminal
4/16/2006 6:57:41 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

5 Replies
855 Views

Similar Articles

[PageSpeed] 48

How do you know that no exception is happening and can you show the code you have in the try and catch block and tell us at what point during page processing the try catch block appears?

If this post answered your question please remember to 'Mark as Answer'!
0
bpag
4/17/2006 2:15:52 AM

Response.Redirect will throw a "Thread was being aborted" Exception. This is by design. So when you use the code like below:

try
        {
            Response.Redirect("Default.aspx");
        }
        catch(Exception ex)
        {
            Response.Redirect("Default2.aspx");
        }

The first Response.Redirect will throw an exception and then turn to the "catch" mode.

0
zhuhua1006
4/17/2006 2:26:23 AM
Just as I thought. An exception was being thrown! I just had no idea that Response.Redirect was causing it  Surprise [:O]

Good info to know zhuhua1006.

If this post answered your question please remember to 'Mark as Answer'!
0
bpag
4/17/2006 2:38:27 AM

I got it working by doing Response.Redirect("default.aspx", False).

it now works properly.

0
thedodgecriminal
4/17/2006 4:05:47 PM

It would really be interesting to know why, by default, the endResponse property is true since this will always throw an exception...right?  Doesn't this kill performance if you use Response.Redirect many times in an application from a .NET CLR Exception counter perspective?

We have an application in this scenario and have to change hundreds of calls to add the false overload since performance was being degraded so badly due to ThreadAbortExceptions alone.

Thanks for any input!

0
sjd0103
6/9/2006 4:01:42 PM
Reply:

Similar Artilces:

try catch finally / response.redirect / response.end flow control question
Hi Guys, Can any one tell me if the finally block would be executed in the following example (assuming that dbReader.read() returned false because no records were found).   Many Thanks! DanielTry dbCon = New SqlConnection(myconnectionstring) dbCon.Open() dbCom = dbCon.CreateCommand() strSQL + "SELECT * FROM bookings WHERE ID > 9000" dbCom.CommandText = strSQL dbReader = dbCom.ExecuteReader() If dbReader.Read() Then 'init fields Else Response.Redirect("main.aspx") End if Finally dbReader.clo...

How do I do a try catch for web form?
Hi, I do this all the time for windows forms, and I put this code into the code behind for web forms and I get no errors, but it doesnt work, is there a way to do a try catch for asp.net web forms? I use vb.net code behind, thanks! Try Cmd.ExecuteNonQuery() Catch ex As Exception MsgBox("Error: " & ex.message) End Try You cant use MsgBox in ASP.NET.. thats a winform thingy.. Use javascript alert() instead. ...

Try..Catch and Response.Redirect
I have sub that connect to a db to verify users. If the user is cleared the they are redirected to the next page and if not then they are forced to login again. I have noticed that during debug on my Try..Catch..Finally block an error is always fired on the resposne.redirect. Dim rs As SqlDataReader = objCMD.ExecuteReader If rs.Read() = False Then Response.Redirect("issuenewrga.aspx?OrderNum=" & txtOrderNum.Text & "&ItemNum=" & txtItemNum.Text & "&LineNum=" & txtLineNum.Text) ...

Try catch in web form
Hi I have a try catch in a (web form) method..now I want to implement a finally and in this check if there are any exceptions thrown .. if yes I have to do some processing in the finally block.  My question is how can I check in Finally if there are any exceptions been thrown at all . Thanks Exceptions that are thrown will be caught in the catch block, so that is where you will process your exceptions. Finally is used for things such as closing database connections and disposing of objects.Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a qu...

non .net form issue within a .net form tag
this may be a bad question... but I am adding a shopping cart to my asp.net website and it calls for the following code for the 'buy now' buttons: <form method="POST" action=http://www.cart.net/cart.aspx/CartName><input type="hidden" name="ID" value="IDName"><input type="hidden" name="Describe" value="IDName Description"><input type="hidden" name="Price" value="100.00"><input type="hidden" name="QtyMax" value="1"><input t...

web.config
I'm working an a SSO project.  On all of the sites, the forms login url is the login website. (login.mydomain.com), I'm redirected to the login page fine, but the ReturnUrl is just the page name, so if I'm on www.mydomain.com/Test.aspx, the ReturnUrl = /Test.aspx, not http://www.mydomain.com/Test.aspx.  I though an easy fix would be to catch this redirect in the global.asax and modify the url that I'm redirecting to for login, but I can't seem to find how to do it.  I'm also up for a better solution if someone has a tried and proven one.  Th...

response.redirect inside a Try Catch...
I’ve come across a situation where I have a response.redirect inside a TRY Catch The redirect seams to trigger an exception.   I found a work around but I’m scared it might cause other problems.   Response.redirect(“blah blah”, False)    ß the false seams to help … although I’m not 100% sure why …   You guys see any problem in this solution?   It should be ok. The second argument means whether the execution of the current page should be stopped or not. When you specified false, it means if should not stop and thus no error otherwise previosly it...

try, catch, Response.Redirect problem
Hi,This is the code which makes me a problem: try{ Response.Redirect("SomePage.aspx");}catch{ ...someOperation():} It always goes to catch region...  i think you don't have that page in your web server. check it first.Got what you needed. Please mark as answer. This is a known issue, try to use the below code try {Response.Redirect("WebForm2.aspx",false);     }catch(Exception ex) { Response.Write(ex.Message); } HCHaissam Abdul MalakMCAD.NET| Blog | Sathesh_pandian:i think you don't have that page in your we...

Try catch, Response.Redirect, and endResponse
 Hi,I get an error email from this aspx page once a while. I have pasted the code skeleton below. The error email says the error occured at the line marked *, where sproc1 is being called. When I look up the database table, I see the sproc2 has been executed as well. I created a test page and changing the endResponse parameter to true or false did not make any difference, when an exception occurs the execution always jumps straight to the catch block. I wish the same thing was happening in the production page as well, but the sproc2 is always being called.try{    .....&nb...

Response.Redirect and Try Catch Finally
If I have a Try Catch Finally block with a Response.Redirect in the Catch and a Connection.Close in the Finally, will the code in the Finally still execute before the Redirect takes place? Someone asked a similar question at this web site: http://www.error-bank.com/microsoft.public.dotnet.languages.vb.1/190535_Thread.aspxDarrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! Thanks for the link. Can anyone confirm that, yes, the Finally will execute? Yes,it will execute....

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Response.Redirect inside a Try Catch block
Can you put a Response.Redirect inside a Try Catch block?I think you will get a thread Abored Error, true? Who said so? I just tried it and it worked fine!!!!What is mainly the problem you are facing?RegardsBilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP...

Response.redirect without exception in a try catch?
I have these code: try{ if(!fuFaxnummer.PostedFile.FileName.EndsWith(".csv")){ Response.Redirect("faxnummerimport.aspx?ID=" + id + "&msg=2"); } //code to execute when the file is a .csv } catch (exception ex){ LogDA.insertLog(...); Response.Redirect("error.aspx"); }I know that "Response.Redirect" gives an Exception. When I set the bool endResponse at false (Response.redirect("",false)) there is no exception BUT he execute the code behind my IF(). Someone with a solution?      ...

web form
I have a web form with some text boxes with validation to ensure that data has been entered. I have two buttons one for "submit" and one for "Return to main". When I click on submit - all works OK as it should with asking the user to enter data for the text boxes. However, when I click "Return to main", instead of redirecting to the main page, the validation requirements for the form appear. Here is some of my code... <table> <tr> <td valign="top" style="width: 318px"><asp:TextBox id="txtTextBox1" runat=&quo...

Web resources about - Response.Redirect within Try Catch - asp.net.web-forms

Wikipedia:Abuse response - Wikipedia, the free encyclopedia
For a list of current Abuse Response volunteers, or for information on how you can help with the Abuse Response project, please see the volunteers ...

George Pell’s Melbourne Response child sexual abuse program
THE victims of child sexual abuse within the Catholic Church just want to be heard.

'God isn't fixing this': US politicians condemned for response to latest mass shooting
In the aftermath of a serious tragedy, it's good advice not to reach for cliche. Particularly when those words aren't followed by action.

'Ugliest girls' poll: Student's response to cyberbullying goes viral
A Torbay, N.L., high school student's response to online bullying is winning praise from friends and family.

Weak response causes Ford to drop Friends & Neighbors sale
... , Ford Ford is canning its unpopular Friends & Neighbors program long before its January termination date, with one dealer citing a poor response ...

Santa lookalike has perfect response to little boy in restaurant
Customers "teary-eyed" over elderly man's reaction to young boy in doughnut shop

The Murders At Planned Parenthood And The Unbelievable GOP Response
Yesterday on Morning Joe , Joseph McQuaid, the publisher of the New Hampshire Union Leader, was asked why his newspaper was endorsing Chris Christie ...

Play Darth Vader with Siri and get some hilarious responses
The whole tech world is losing its mind with Star Wars mania, and Apple’s no exception. Hidden within Siri is a neat reference to George Lucas’ ...

Democratic Senator: Prayers Are ‘Wholly Insufficient’ Responses To Shootings
Democratic Senator: Prayers Are ‘Wholly Insufficient’ Responses To Shootings

Disaster-Response Robots Demonstrate Their Skills
This year's International Robot Exhibition in Tokyo is focused on robotic equipment for disaster relief.

Resources last updated: 12/7/2015 4:33:44 AM