By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,137 Members | 2,282 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,137 IT Pros & Developers. It's quick & easy.

Cancel a Response.Redirect

P: n/a
Tim
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
Nov 18 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
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

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
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

Nov 18 '05 #2

P: n/a
Tim
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

"Curt_C [MVP]" wrote:
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

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
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


Nov 18 '05 #3

P: n/a
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.
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
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

Nov 18 '05 #4

P: n/a
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
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
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

"Curt_C [MVP]" wrote:
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

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
> 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


Nov 18 '05 #5

P: n/a
Tim
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

"Curt_C [MVP]" wrote:
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
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
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

"Curt_C [MVP]" wrote:
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

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
> 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


Nov 18 '05 #6

P: n/a
Tim
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

"Enrique Santa Cruz" wrote:
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.
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
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


Nov 18 '05 #7

P: n/a
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
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
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

"Curt_C [MVP]" wrote:
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
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
> 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
>
> "Curt_C [MVP]" wrote:
>
>> 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
>>
>> --
>> Curt Christianson
>> Owner/Lead Developer, DF-Software
>> Site: http://www.Darkfalz.com
>> Blog: http://blog.Darkfalz.com
>>
>>
>> "Tim" <Ti*@discussions.microsoft.com> wrote in message
>> news:6F**********************************@microsof t.com...
>> > 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
>>
>>
>>


Nov 18 '05 #8

P: n/a
Just comment out the redirect, and write an entry to the event log, text
file or database instead.

Jeff
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
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

"Curt_C [MVP]" wrote:
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

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
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


Nov 18 '05 #9

P: n/a
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?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 4 Nov 2004 12:40:02 -0800, Tim <Ti*@discussions.microsoft.com>
wrote:
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


Nov 18 '05 #10

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

Tim
"Scott Allen" wrote:
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?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 4 Nov 2004 12:40:02 -0800, Tim <Ti*@discussions.microsoft.com>
wrote:
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


Nov 18 '05 #11

P: n/a
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
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
Hey Scott,
I have another class in a web application that calls that page like:
WebForm1 p = new WebForm1();
p.SomeMethodOnWebForm1();

Tim
"Scott Allen" wrote:
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?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 4 Nov 2004 12:40:02 -0800, Tim <Ti*@discussions.microsoft.com>
wrote:
Thanks - but that would require me to change the original page that is beingtested, which I cannot do. All my code is limited to the unit-test that callsthe page.

Tim


Nov 18 '05 #12

P: n/a
Tim
> 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

"Jeff Dillon" wrote:
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
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
Hey Scott,
I have another class in a web application that calls that page like:
WebForm1 p = new WebForm1();
p.SomeMethodOnWebForm1();

Tim
"Scott Allen" wrote:
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?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 4 Nov 2004 12:40:02 -0800, Tim <Ti*@discussions.microsoft.com>
wrote:

>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
>


Nov 18 '05 #13

P: n/a
Um..like someone said earlier??

Just comment out the redirect, and write an entry to the event log, text
file or database instead
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:61**********************************@microsof t.com...
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

"Jeff Dillon" wrote:
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
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
Hey Scott,
I have another class in a web application that calls that page like:
WebForm1 p = new WebForm1();
p.SomeMethodOnWebForm1();

Tim
"Scott Allen" wrote:

> 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?
>
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
> On Thu, 4 Nov 2004 12:40:02 -0800, Tim <Ti*@discussions.microsoft.com> > wrote:
>
> >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
> >
>
>


Nov 18 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.