Cancel a Response.Redirect

G

Guest

Hello,
Is there a way to "cancel" a response.Redirect? For example, in the code
below, could I insert anything in the Catch statement that would cancel the
redirect and resume flow after the try-catch?

Try
Response.Redirect(strPage)
Catch ex1 As Threading.ThreadAbortException
ex1 = ex1
'Cancel Respone here
End Try
'Resume flow here

I am trying to write unit tests for pages that include Redirects.

Thanks for any advice,
Tim
 
C

Curt_C [MVP]

What is it you expect to catch from a Response.Redirect() ?
I suggest you look at a sample of validating a URL instead of the try/catch
on the redirect
 
E

Enrique Santa Cruz

Response.Redirect accepts two parameters the second being to abort the
current thread or continue with execution. Maybe look into that, it might
help your cause.
Enrique.
 
G

Guest

Hello Curt,
I'm trying to "catch" that the page being tested correctly tried to
Redirect to another page.

Can you provide an article that discusses further validating a URL - I'm not
seeing how this would help unit test the page.

Thanks,
Tim
 
C

Curt_C [MVP]

What are you trying to "test"? If the page is there or some processing that
happens on the page?
I mean when you Response.Redirect() there is NO return value, it always
executes, there is nothing to try/catch.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
 
G

Guest

I'm trying to write a unit test to check (1) if page correctly does a
Redirect, (2) Ideally check the value of the page it's trying to redirect to.

Response .Redirect doesn't have a return value, but it does have an affect
--> navigating to a new page. I'm trying to test that the page was about to
do the correct affect (navigate to the new page), and then I want to cancel
that so the main host program can still run all the other tests.

It's seeming like this is very non-standard, and I'll try to find a more
standard approach.

Tim
 
G

Guest

Thanks - but that would require me to change the original page that is being
tested, which I cannot do. All my code is limited to the unit-test that calls
the page.

Tim
 
C

Curt_C [MVP]

That might be best. It's one of those cases where you can't test. I mean you
dont know if it worked till it's on the new page, and at that point the
calling page isn't active anymore.... kind of like testing to see if a gun
fires by firing it... to late to get the bullet back in the gun afterwards.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
 
J

Jeff Dillon

Just comment out the redirect, and write an entry to the event log, text
file or database instead.

Jeff
 
S

Scott Allen

Tim - just curious what / how you are testing the page. With some sort
of HTTP client? Could you look for the 302 redirect response code?
 
G

Guest

Hey Scott,
I have another class in a web application that calls that page like:
WebForm1 p = new WebForm1();
p.SomeMethodOnWebForm1();

Tim
 
J

Jeff Dillon

So you want to change the behavior of the page without changing anything in
the page?

Why can't you change the page? Did you write it? Can you "talk" to the
developers??

Jeff
 
G

Guest

So you want to change the behavior of the page without changing anything in
the page?
No - I want the page to produce the same effect (send an "output" to try to
redirect to another page), but I want to trap that "output" and prevent it
from actually redirecting.

I can't comment out the redirects, but I could have the redirects abstracted
to a method that returns a string, and then I could check the string value to
make sure it's correct.

I can talk to the developers.

Tim
 
J

Jeff Dillon

Um..like someone said earlier??

Just comment out the redirect, and write an entry to the event log, text
file or database instead
 

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

Top